我试图将现有的spring weblogic应用程序转换为spring boot embedded tomcat应用程序。将weblogic spring web应用程序转换为springboot应用程序的CGLIB错误
有很多移动部件,所以很难显示任何代码,我希望有一些一般的答案可能会提示我这个问题。
在weblogic下,使用spring-framework 4.3.6.RELEASE库,应用程序部署得很好。创建不同的服务,存储库和组件bean没有问题。
然而,当我把它迁移到春季启动1.5.1.RELEASE,我得到以下错误:
2017-06-21 17:08:16,402 [ERROR] SpringApplication reportFailure (815) - Application startup failed
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'alertEventServiceImpl': Unsatisfied dependency expressed through field 'alertEventDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'alertEventDaoImpl' defined in URL [jar:file:/Users/username/Development/source/carma-war/target/carma-war-2.0.0-SNAPSHOT.war!/WEB-INF/lib/protocol-manager-1.8.0-SNAPSHOT.jar!/org/ihc/hwcir/protocol/dao/AlertEventDaoImpl.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class org.ihc.hwcir.protocol.dao.AlertEventDaoImpl]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Cannot subclass final class org.ihc.hwcir.protocol.dao.AlertEventDaoImpl
我们的很多服务类的都最终,因为他们不应该被延长。由于有很多是最终的,所以我想尽量减少我们修改的不同库中的代码数量,以使其工作。
我认为是因为bean的创建过程在weblogic下工作,所以它应该在spring引导下工作。
事情我已经尝试不使用CGLIB代理给力:
- 所有实现实现接口已经
- 在通过XML创建豆类,补充
<aop:scoped-proxy proxy-target-class="false"/>
- 在通过注释创建豆类,补充(例如服务豆)
@Service @Scope(proxyMode = ScopedProxyMode.INTERFACE)
然而,最终,我对Spring为什么会在weblogic容器下创建bean(标记为final的类)感到困惑,但在嵌入式tomcat spring-boot容器下无法做到这一点。
在您的Web逻辑容器中,它不使用CGLIB,而是基于接口的JDK Dynamic代理。 Spring Boot强制使用类代理,并禁用您需要修改配置的功能。此外,您不使用作用域代理,因此将其设置为false并不会产生影响。您必须更改事务处理,重写JPA设置等的一些配置以使基于接口的代理。例如见[this](https://github.com/spring-projects/spring-boot/issues/8434)问题。 –
对于Spring Boot 1.5,你应该在'application.properties'中设置'spring.aop.proxy-target-class = false',你应该很好。默认是'true'。 –