简体   繁体   English

Spring应用程序有Cglib2AopProxy警告

[英]Spring application has Cglib2AopProxy warnings

Upon starting my application, I get numerous warnings along 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.' 在开始我的应用程序时,我收到了许多警告, 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 or so functions. 大约十几个功能。

Now I perfectly understand that proxy-based aspects cannot be applied to final methods. 现在我完全理解基于代理的方面不能应用于最终方法。 However, I did not (on purpose, at least) try to weave any aspects into JdbcDaoSupport . 但是,我没有(至少是故意的)尝试将任何方面编织到JdbcDaoSupport I suspect it comes from <tx:annotation-driven /> . 我怀疑它来自<tx:annotation-driven /> Is there anything I can do to silence these warnings or, better yet, exclude those classes from the aspect weaving? 我可以采取哪些措施来消除这些警告,或者更好的是,将这些类别排除在编织方面?

This is most likely caused by the @Transactional annotation, Spring wraps your DAO in a proxy to add the transactional behavior. 这很可能是由@Transactional注释引起的,Spring将DAO包装在代理中以添加事务行为。

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. 我建议让你的DAO实现一个接口( 为你的DAO创建和使用一个接口 ),这将允许Spring使用JDK动态代理而不必使用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. 使用CGLIB有一个限制,即无法建议在目标类中标记为final的方法,因为无法覆盖最终方法(CGLIB在运行时创建目标类的子类),但在使用JDK动态代理的情况下,此限制将消失。

Reference 参考

Maybe you have extended JdbcDaoSupport and added @Transactional annotations. 也许您已经扩展了JdbcDaoSupport并添加了@Transactional注释。

You can set the Cglib2AopProxy logger to log level ERROR to avoid the warn messages. 您可以将Cglib2AopProxy记录器设置为日志级别ERROR以避免警告消息。 For example if using log4j and log4j.properties: 例如,如果使用log4j和log4j.properties:

log.logger.org.springframework.aop.framework.Cglib2AopProxy = ERROR

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. 并且请投票支持IntelliJ的检查的功能请求,这可以帮助我们避免这个警告。 BTW It also contains a good explanation. BTW它还包含一个很好的解释。

Spring Boot now uses CGLIB proxying by default, including for the AOP support. Spring Boot现在默认使用CGLIB代理,包括AOP支持。 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。

spring.aop.proxy-target-class=false spring.aop.proxy目标级=假

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM