Spring application has Cglib2AopProxy warnings

后端 未结 4 641
夕颜
夕颜 2020-12-28 17:26

Upon starting my application, I get numerous warnings along the lines of o.s.aop.framework.Cglib2AopProxy \'Unable to proxy method [public final void org.springframewo

相关标签:
4条回答
  • 2020-12-28 18:15

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

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

    Using CGLIB has a limitation that methods marked as final in target class can’t be advised as final methods can’t be overridden (CGLIB creates a subclass of target class at runtime) but this limitation disappears in case of using JDK dynamic proxies.

    Reference

    0 讨论(0)
  • 2020-12-28 18:15

    Spring Boot now uses CGLIB proxying by default, including for the AOP support. If you need interface-based proxy, you’ll need to set the spring.aop.proxy-target-class to false.

    spring.aop.proxy-target-class=false

    0 讨论(0)
  • 2020-12-28 18:27

    Maybe you have extended JdbcDaoSupport and added @Transactional annotations.

    You can set the Cglib2AopProxy logger to log level ERROR to avoid the warn messages. For example if using log4j and log4j.properties:

    log.logger.org.springframework.aop.framework.Cglib2AopProxy = ERROR
    
    0 讨论(0)
  • 2020-12-28 18:29

    You should use interfaces for dependency injection, the most reasons for this are described here and here.

    You can read documentation about proxying mechanic for details why you see this warning.

    And please vote for feature request of inspection for IntelliJ that may helps us to avoid this warnings. BTW It also contains a good explanation.

    0 讨论(0)
提交回复
热议问题