Spring引导 - 无法代理接口实现方法 - WARN消息

时间:2018-03-17 17:30:05

标签: spring spring-boot cglib

人。 从Spring boot 1.5.x开始,我收到以下WARN消息:

     :: Spring Boot ::        (v2.0.0.RELEASE)

2018-03-17 18:58:18.546  WARN 27877 --- [  restartedMain] o.s.a.f.CglibAopProxy                    : Unable to proxy interface-implementing method [public final void org.springframework.web.context.support.WebApplicationObjectSupport.setServletContext(javax.servlet.ServletContext)] because it is marked as final: Consider using interface-based JDK proxies instead!
2018-03-17 18:58:18.551  WARN 27877 --- [  restartedMain] o.s.a.f.CglibAopProxy                    : Unable to proxy interface-implementing method [public final void org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext) throws org.springframework.beans.BeansException] because it is marked as final: Consider using interface-based JDK proxies instead!
2018-03-17 18:58:18.937  WARN 27877 --- [  restartedMain] o.s.a.f.CglibAopProxy                    : Unable to proxy interface-implementing method [public final void org.springframework.web.context.support.WebApplicationObjectSupport.setServletContext(javax.servlet.ServletContext)] because it is marked as final: Consider using interface-based JDK proxies instead!
2018-03-17 18:58:18.938  WARN 27877 --- [  restartedMain] o.s.a.f.CglibAopProxy                    : Unable to proxy interface-implementing method [public final void org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext) throws org.springframework.beans.BeansException] because it is marked as final: Consider using interface-based JDK proxies instead!
2018-03-17 18:58:19.034  WARN 27877 --- [  restartedMain] o.s.a.f.CglibAopProxy                    : Unable to proxy interface-implementing method [public final void org.springframework.web.context.support.WebApplicationObjectSupport.setServletContext(javax.servlet.ServletContext)] because it is marked as final: Consider using interface-based JDK proxies instead!
2018-03-17 18:58:19.035  WARN 27877 --- [  restartedMain] o.s.a.f.CglibAopProxy                    : Unable to proxy interface-implementing method [public final void org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext) throws org.springframework.beans.BeansException] because it is marked as final: Consider using interface-based JDK proxies instead!
2018-03-17 18:58:19.136  WARN 27877 --- [  restartedMain] o.s.a.f.CglibAopProxy                    : Unable to proxy interface-implementing method [public final void org.springframework.web.context.support.WebApplicationObjectSupport.setServletContext(javax.servlet.ServletContext)] because it is marked as final: Consider using interface-based JDK proxies instead!
2018-03-17 18:58:19.136  WARN 27877 --- [  restartedMain] o.s.a.f.CglibAopProxy                    : Unable to proxy interface-implementing method [public final void org.springframework.context.support.ApplicationObjectSupport.setApplicationContext(org.springframework.context.ApplicationContext) throws org.springframework.beans.BeansException] because it is marked as final: Consider using interface-based JDK proxies instead!

我没有依赖层次结构中的CGLIB。我只使用DI接口,我试图禁用@EnableGlobalMethodSecurity(securedEnabled = true)以及与之相关的所有内容,但仍然没有变化。(我已经读过MethodSecurity和@Secured注释在Controller类中可以引起这种警告,但似乎我从另一个地方获取它们。 如何知道从哪里收到这些警告?

3 个答案:

答案 0 :(得分:1)

问题在于Class级别的一些@Transactional注释。我把它们放在接口上(存储库 - 我使用弹簧数据)一切都OK:)

答案 1 :(得分:0)

根据报告的问题,我遇到了类似于使用最终的接口实现方法的问题。

从具体类(Bean)中,如果我们从方法中删除final,也解决了同样的问题。

价: https://github.com/spring-projects/spring-boot/issues/8974

答案 2 :(得分:0)

在检查 @Transactional 注释后,确保您将 @Repository 注释直接放入存储库界面。就我而言,我执行了以下操作:

  1. 从我的 DAO 类
  2. 中删除了 @Transactional@Repository
  3. @Repository 放入我的 repo 界面
  4. @Component 放入我的 DAO 类

有关注释的详细信息,请参阅 Spring Boot + Annotations