I am attempting to convert an existing spring weblogic application to a spring boot embedded tomcat application.
我试图将现有的spring weblogic应用程序转换为spring boot嵌入式tomcat应用程序。
There are lots of moving parts so it's hard to show any code, I'm hoping there is some general answer that might clue me in to the issue.
有很多移动部件,所以很难显示任何代码,我希望有一些一般的答案可能会让我知道这个问题。
Under weblogic, using the spring-framework 4.3.6.RELEASE libraries, the application deploys fine. It has no problems creating the different service, repository and component beans.
在weblogic下,使用spring-framework 4.3.6.RELEASE库,应用程序可以正常部署。创建不同的服务,存储库和组件bean没有问题。
However, when I migrate it to Spring Boot 1.5.1.RELEASE, I get the following error:
但是,当我将它迁移到Spring Boot 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
Many of our service classes are final as they shouldn't be extended. Since there are so many that are final, I wanted to minimize the amount of code in our different libraries that we modify to make this work.
我们的许多服务类都是最终的,因为它们不应该被扩展。由于有很多是最终的,我想尽量减少我们修改的不同库中的代码量,以使其工作。
I thought because the bean creation process works under weblogic, it should work under spring boot.
我认为因为bean创建过程在weblogic下工作,它应该在spring boot下工作。
Things I have tried to force not using the cglib proxies:
我试图强制不使用cglib代理的事情:
- All implementations implement interfaces already
- In beans created via xml, added
<aop:scoped-proxy proxy-target-class="false"/>
- In beans created through annotations, added (example for service bean)
所有实现都已实现接口
在通过xml创建的bean中,添加了
在通过注释创建的bean中,添加了(服务bean的示例)
@Service @Scope(proxyMode = ScopedProxyMode.INTERFACE)
@Service @Scope(proxyMode = ScopedProxyMode.INTERFACE)
However, in the end, I'm perplexed as to why spring can create beans (the classes marked as final) under the weblogic container but unable to do so under the embedded tomcat spring-boot container.
但是,最后,我很困惑为什么spring可以在weblogic容器下创建bean(标记为final的类)但在嵌入式tomcat spring-boot容器下无法创建bean。
2 个解决方案
#1
0
Spring Boot by default uses class based proxies, which will not work with final
classes/methods.
Spring Boot默认使用基于类的代理,这不适用于最终的类/方法。
To disable this add spring.aop.proxy-target-class=false
to the application.properties
to enable JDK Dynamic Proxies instead of class based proxies. (And revert your modifications).
要禁用此功能,请将spring.aop.proxy-target-class = false添加到application.properties以启用JDK Dynamic Proxies而不是基于类的代理。 (并恢复您的修改)。
NOTE: To have everything take into account the spring.aop.proxy-target-class
you might need to upgrade to Spring Boot 1.5.3 as some final patches where made to include this property in parts that were missed in previous versions.
注意:要让所有内容都考虑到spring.aop.proxy-target-class,您可能需要升级到Spring Boot 1.5.3作为一些最终补丁,以便在以前版本中遗漏的部分中包含此属性。
See the following issues for more information 8434, 8869 and 8887.
有关更多信息,请参阅以下问题:8434,8869和8887。
#2
0
I was unable to make this work using M. Deinums' answer using spring.aop.proxy-target-class=false.
我使用Spring.aop.proxy-target-class = false使用M. Deinums的答案无法完成这项工作。
What worked for me was to add in the application.properties file
对我有用的是添加application.properties文件
spring.dao.exceptiontranslation.enabled=false
Please note that this option disables proxy creation for repositories.
请注意,此选项禁用存储库的代理创建。
And in my spring boot application configurer the annotation to handle transactions without using a proxy class.
在我的spring boot应用程序中,配置注释以在不使用代理类的情况下处理事务。
@EnableTransactionManagement(proxyTargetClass = false)
This is using Spring Boot version 1.5.1.RELEASE.
这是使用Spring Boot版本1.5.1.RELEASE。
#1
0
Spring Boot by default uses class based proxies, which will not work with final
classes/methods.
Spring Boot默认使用基于类的代理,这不适用于最终的类/方法。
To disable this add spring.aop.proxy-target-class=false
to the application.properties
to enable JDK Dynamic Proxies instead of class based proxies. (And revert your modifications).
要禁用此功能,请将spring.aop.proxy-target-class = false添加到application.properties以启用JDK Dynamic Proxies而不是基于类的代理。 (并恢复您的修改)。
NOTE: To have everything take into account the spring.aop.proxy-target-class
you might need to upgrade to Spring Boot 1.5.3 as some final patches where made to include this property in parts that were missed in previous versions.
注意:要让所有内容都考虑到spring.aop.proxy-target-class,您可能需要升级到Spring Boot 1.5.3作为一些最终补丁,以便在以前版本中遗漏的部分中包含此属性。
See the following issues for more information 8434, 8869 and 8887.
有关更多信息,请参阅以下问题:8434,8869和8887。
#2
0
I was unable to make this work using M. Deinums' answer using spring.aop.proxy-target-class=false.
我使用Spring.aop.proxy-target-class = false使用M. Deinums的答案无法完成这项工作。
What worked for me was to add in the application.properties file
对我有用的是添加application.properties文件
spring.dao.exceptiontranslation.enabled=false
Please note that this option disables proxy creation for repositories.
请注意,此选项禁用存储库的代理创建。
And in my spring boot application configurer the annotation to handle transactions without using a proxy class.
在我的spring boot应用程序中,配置注释以在不使用代理类的情况下处理事务。
@EnableTransactionManagement(proxyTargetClass = false)
This is using Spring Boot version 1.5.1.RELEASE.
这是使用Spring Boot版本1.5.1.RELEASE。