ARTICLE AD BOX
We mostly use Jdbi.onDemand with DAO interfaces to interact with our RDS.
I'm trying to get visibility of when each DAO method is invoked.
We have hundreds of methods across dozens of interfaces, so adding logs to every invocation individually is impractical.
I was hoping to use an AOP advice based on JDBI annotations on the interface methods. We have @annotation advice for some controller methods, which works well, but the same approach isn't working for DAO methods.
I suspect this is because both Spring AOP and JDBI work by creating proxy classes based on the interface, so that JDBI is able to get an instance and use it to interact with the database, but my aspect can't "see" that instance to apply the advice. I'm pretty new to this though and still getting my head round the details.
Example code snippets (simplified):
@Service public class MyService { private Jdbi jdbi; public Long getCount() { // MyDAO#getCount is invoked as expected return jdbi.onDemand(MyDAO.class).getCount(); } } public interface MyDAO { @SqlQuery("SELECT COUNT(*) FROM myschema.mytable") public Long getCount(); } @Aspect @Component public class MyAspect { @Before("@annotation(sqlQuery)") public void queryAdvice(SqlQuery sqlQuery) { // When the service method is invoked, I expect this to be printed, but nothing happens System.out.println("Executing query: " + sqlQuery.value()); } }I've tried different advice types, different pointcut expressions including bean and execution, using a separate pointcut method, using a custom annotation instead of the JDBI one. Nothing I've tried seems to make any difference.
Is there a workaround or a way to configure the aspect/interface so that JDBI's on-demand extension can interact with AspectJ/Spring AOP/any other aspect-oriented framework?
