Spring application has Cglib2AopProxy warnings

When I launch the application, I get a lot of warnings in the lines of osaop.framework.Cglib2AopProxy 'Unable to proxy method [public final void org.springframework.jdbc.core.support.JdbcDaoSupport.setDataSource(javax.sql.DataSource)] because it is final: All calls to this method via a proxy will be routed directly to the proxy.' for about a dozen functions.

Now I understand very well that proxy-based aspects cannot be applied to final methods. However, I (at least I don't intend) tried to weave any aspects into JdbcDaoSupport . I suspect this comes from <tx:annotation-driven /> . Is there anything I can do to silence these warnings or, even better, to exclude these classes from the weaving aspect?

+15
spring spring-aop spring-transactions
Oct 02
source share
4 answers

You might have expanded JdbcDaoSupport and added @Transactional annotations.

You can set the Cglib2AopProxy Cglib2AopProxy to the ERROR log level to avoid warning messages. For example, if you use log4j and log4j.properties:

 log.logger.org.springframework.aop.framework.Cglib2AopProxy = ERROR 
+3
Oct 02
source share

This is most likely due to the @Transactional annotation, Spring wraps your DAO in a proxy to add transactional behavior.

I would recommend that your DAO implement an interface ( create and use an interface for your DAO ), this will allow Spring to use a dynamic JDK proxy instead of using CGLib.

The use of CGLIB is limited to the fact that methods marked final in the target class can be recommended, since the final methods cannot be overridden (CGLIB subclasses the target class at run time), but this restriction disappears when using dynamic JDK proxies.

Link

+16
Oct 02
source share

You should use interfaces to implement dependencies, most of the reasons for this are described here and here .

You can read the proxy mechanics documentation to find out why you see this warning.

And please vote on for a special IntelliJ review request that can help us avoid this warning. By the way, this also contains a good explanation.

+1
Sep 22 '15 at 11:49
source share

Spring Boot now uses the default CGLIB proxy, including to support AOP. If you need an interface proxy, you need to set false in spring.aop.proxy-target-class to false.

spring.aop.proxy-target class = false

0
Apr 29 '19 at 9:13
source share



All Articles