2017-06-21 109 views
0

我试图将现有的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代理给力:

  1. 所有实现实现接口已经
  2. 在通过XML创建豆类,补充<aop:scoped-proxy proxy-target-class="false"/>
  3. 在通过注释创建豆类,补充(例如服务豆)

@Service @Scope(proxyMode = ScopedProxyMode.INTERFACE)

然而,最终,我对Spring为什么会在weblogic容器下创建bean(标记为final的类)感到困惑,但在嵌入式tomcat spring-boot容器下无法做到这一点。

+0

在您的Web逻辑容器中,它不使用CGLIB,而是基于接口的JDK Dynamic代理。 Spring Boot强制使用类代理,并禁用您需要修改配置的功能。此外,您不使用作用域代理,因此将其设置为false并不会产生影响。您必须更改事务处理,重写JPA设置等的一些配置以使基于接口的代理。例如见[this](https://github.com/spring-projects/spring-boot/issues/8434)问题。 –

+0

对于Spring Boot 1.5,你应该在'application.properties'中设置'spring.aop.proxy-target-class = false',你应该很好。默认是'true'。 –

回答

0

我无法使用M. Deinums的答案使用spring.aop.proxy-target-class = false进行此项工作。

什么工作对我来说是在application.properties添加文件

spring.dao.exceptiontranslation.enabled=false 

请注意,此选项禁用库代理的创建。

而在我的spring引导应用程序配置注释来处理事务而不使用代理类。

@EnableTransactionManagement(proxyTargetClass = false) 

这是使用Spring Boot版本1.5.1.RELEASE。

0

默认情况下,Spring Boot使用基于类的代理,这不适用于类/方法final

要禁用此功能,请将spring.aop.proxy-target-class=false添加到application.properties以启用JDK Dynamic Proxies而不是基于类的代理。 (并恢复您的修改)。

注:拥有一切考虑到您可能需要升级到春季启动1.5.3为其中提出以包括被遗漏在以前版本的部分该物业的一些最后的补丁spring.aop.proxy-target-class

有关更多信息,请参阅以下问题8434,88698887

+0

不幸的是,没有做到这一点。是什么让它工作是这个设置,不知道为什么。 spring.dao.exceptiontranslation.enabled = false ...你知道吗? 但是,您处理交易管理者的另一个问题的链接是正确的。我很高兴接受这个答案,如果你添加你的链接并且让我明白为什么exceptiontranslation.enabled = false工作而不是aop.proxy-target-class。 – Johnnie

+0

这基本上禁用了存储库的异常转换,因此需要为存储库创建代理。我建议自己配置'PersistenceExceptionTranslationPostProcessor'并将'proxyTargetClass'属性设置为false,而不是禁用。 (除了'spring.aop.proxy-target-class = true'。 –

+0

这基本上禁用了存储库的异常转换,因此需要为存储库创建代理,而不是禁止我建议自己配置'PersistenceExceptionTranslationPostProcessor'并将proxyTargetClass属性设置为false(除了'spring.aop.proxy-target-class = false')。'PersistenceExceptionTranslationAutoConfiguration'考虑到了这个属性,所以很奇怪,它不起作用。增加了Spring Boot 1.5.3,所以你可能想升级到最新的1.5.x版本而不是禁用它)。 –

相关问题