Open
Description
I'm currently using the p6spy library very well, and I really appreciate it.
I have one question about it.
Description:
Currently, MessageFormattingStrategy implementations cannot leverage Spring's dependency injection,
making it difficult to integrate with Spring-based applications for advanced use cases like:
- Publishing application events based on query patterns
- Accessing other Spring beans for business logic integration
Current Limitation:
public class CustomFormatter implements MessageFormattingStrategy {
@Autowired // This doesn't work
private ApplicationEventPublisher eventPublisher;
@Override
public String formatMessage(...) {
if (sql.contains("payment_transactions")) {
eventPublisher.publishEvent(new PaymentQueryEvent(sql)); // NPE
}
return this.formatSql(sql);
}
Since P6Spy creates MessageFormattingStrategy instances directly without going through Spring's ApplicationContext, dependency injection via @Autowired annotations is not available.
Is there a way to solve this problem?
Environment:
- Spring Boot: 3.4.5
- com.github.gavlyukovskiy:p6spy-spring-boot-starter:1.11.0
- p6Spy3.9.1
- gradle: 8.12.1
Use Case: detailed query auditing
Metadata
Metadata
Assignees
Labels
No labels