gpt4 book ai didi

java - 升级后,在Eclipse中测试通过,在Maven中失败,Spring抛出BeanCreationException/NoClassDefFoundError $proxy10

转载 作者:行者123 更新时间:2023-12-01 13:08:28 26 4
gpt4 key购买 nike

将 Spring/Hibernate 升级到最新版本后,我在 Maven 下运行测试时遇到了问题。

org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 'protoEntityManager' defined in class path resource [test_config/ioc.xml]:
Invocation of init method failed;
nested exception is java.lang.NoClassDefFoundError:
Could not initialize class $Proxy10
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1512)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:521)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:296)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:293)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:610)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93)
at org.permacode.atomic.AtomicConfigurationBean.getEntityManagerFactory(AtomicConfigurationBean.java:191)
at org.permacode.atomic.ContextManager.getEntityManagerFactory(ContextManager.java:168)
at org.permacode.atomic.ContextManagerTest.test2InstantiateEntityManagerFactory(ContextManagerTest.java:77)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class $Proxy10
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:588)
at org.springframework.aop.framework.JdkDynamicAopProxy.getProxy(JdkDynamicAopProxy.java:119)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:111)
at org.springframework.aop.framework.AbstractSingletonProxyFactoryBean.afterPropertiesSet(AbstractSingletonProxyFactoryBean.java:174)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1571)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1509)
... 45 more

这是我的 Spring 上下文配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean class="org.permacode.atomic.web.AtomicStrutsWrapper"
id="httpServletAccess" autowire="constructor"/>
<bean class="org.permacode.atomic.web.DefaultExceptionHandler"
id="exceptionHandler" autowire="constructor" />
<bean class="org.permacode.atomic.web.ResourceBundleI18nEngine"
id="i18nEngine">
<constructor-arg>
<bean class="org.permacode.atomic.web.StrutsResourceBundleProvider" />
</constructor-arg>
</bean>
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory">
<bean class="org.permacode.atomic.ContextManager"
factory-method="getEntityManagerFactory" />
</property>
</bean>
<bean id="protoDao" class="org.permacode.atomic.jpa.JpaProtoDao"></bean>
<bean id="targetProxyProtoEM" class="org.permacode.atomic.domain.BasicProtoEntityManager">
<constructor-arg ref="protoDao"/>
</bean>
<bean id="baseTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
abstract="true">
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<props>
<prop key="create*">PROPAGATION_REQUIRED</prop>
<prop key="update*">PROPAGATION_REQUIRED</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
<prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
</props>
</property>
</bean>
<bean id="protoEntityManager" parent="baseTransactionProxy">
<property name="target" ref="targetProxyProtoEM" />
</bean>
</beans>

Spring 试图将上下文中的 Spring bean Autowiring 在一起,但在尝试创建事务管理器或事务代理管理器工厂时失败了,目前尚不清楚。

我正在使用以下依赖项:

[INFO] The following files have been resolved:
[INFO] antlr:antlr:jar:2.7.7:compile
[INFO] aopalliance:aopalliance:jar:1.0:compile
[INFO] cglib:cglib:jar:3.1:compile
[INFO] cglib:cglib-nodep:jar:2.1_3:test
[INFO] com.h2database:h2:jar:1.0.64:test
[INFO] com.opensymphony:xwork:jar:2.1.2:compile
[INFO] com.sun:tools:jar:1.5.0:system
[INFO] commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] commons-collections:commons-collections:jar:3.2:compile
[INFO] commons-configuration:commons-configuration:jar:1.5:compile
[INFO] commons-dbutils:commons-dbutils:jar:1.1:compile
[INFO] commons-digester:commons-digester:jar:1.8:compile
[INFO] commons-fileupload:commons-fileupload:jar:1.2.1:compile
[INFO] commons-io:commons-io:jar:1.3.1:compile
[INFO] commons-lang:commons-lang:jar:2.4:compile
[INFO] commons-logging:commons-logging:jar:1.1.1:compile
[INFO] commons-logging:commons-logging-api:jar:1.1:compile
[INFO] commons-pool:commons-pool:jar:1.5.4:compile
[INFO] dom4j:dom4j:jar:1.6.1:compile
[INFO] hsqldb:hsqldb:jar:1.8.0.7:test
[INFO] httpunit:httpunit:jar:1.6.2:test
[INFO] javax.servlet:jstl:jar:1.1.2:compile
[INFO] javax.servlet:servlet-api:jar:2.5:provided
[INFO] javax.servlet.jsp:jsp-api:jar:2.1:provided
[INFO] javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] jtidy:jtidy:jar:4aug2000r7-dev:test
[INFO] junit:junit:jar:4.8.2:test
[INFO] mysql:mysql-connector-java:jar:5.0.5:test
[INFO] net.sourceforge.serp:serp:jar:1.14.1:compile
[INFO] opensymphony:ognl:jar:2.6.11:compile
[INFO] org.apache.derby:derby:jar:10.3.2.1:test
[INFO] org.apache.geronimo.specs:geronimo-jms_1.1_spec:jar:1.1.1:compile
[INFO] org.apache.geronimo.specs:geronimo-jpa_2.0_spec:jar:1.1:compile
[INFO] org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1:compile
[INFO] org.apache.openjpa:openjpa:jar:2.3.0:compile
[INFO] org.apache.struts:struts2-core:jar:2.1.6:compile
[INFO] org.apache.struts:struts2-tiles-plugin:jar:2.1.6:compile
[INFO] org.apache.tiles:tiles-api:jar:2.0.6:compile
[INFO] org.apache.tiles:tiles-core:jar:2.0.6:compile
[INFO] org.apache.tiles:tiles-jsp:jar:2.0.6:runtime
[INFO] org.apache.tomcat:annotations-api:jar:6.0.13:test
[INFO] org.apache.tomcat:catalina:jar:6.0.13:test
[INFO] org.apache.tomcat:el-api:jar:6.0.13:test
[INFO] org.apache.tomcat:jasper:jar:6.0.13:test
[INFO] org.apache.tomcat:jasper-el:jar:6.0.13:test
[INFO] org.apache.tomcat:jasper-jdt:jar:6.0.13:test
[INFO] org.apache.tomcat:jsp-api:jar:6.0.13:test
[INFO] org.apache.tomcat:juli:jar:6.0.13:test
[INFO] org.apache.tomcat:servlet-api:jar:6.0.13:test
[INFO] org.apache.xbean:xbean-asm4-shaded:jar:3.14:compile
[INFO] org.aspectj:aspectjrt:jar:1.7.4:compile
[INFO] org.easymock:easymock:jar:2.3:test
[INFO] org.easymock:easymockclassextension:jar:2.2.2:test
[INFO] org.eclipse.persistence:javax.persistence:jar:2.0.0:compile
[INFO] org.freemarker:freemarker:jar:2.3.13:compile
[INFO] org.hibernate:hibernate-core:jar:4.2.11.Final:compile
[INFO] org.hibernate:hibernate-entitymanager:jar:4.2.11.Final:compile
[INFO] org.hibernate.common:hibernate-commons-annotations:jar:4.0.2.Final:compile
[INFO] org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO] org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] org.ow2.asm:asm:jar:4.2:compile
[INFO] org.ow2.easybeans:easybeans-jpa-eclipselink:pom:1.2.1:compile
[INFO] org.permacode:permacode:jar:1.0.0:compile
[INFO] org.slf4j:jcl-over-slf4j:jar:1.7.6:runtime
[INFO] org.slf4j:slf4j-api:jar:1.7.6:compile
[INFO] org.slf4j:slf4j-simple:jar:1.6.1:compile
[INFO] org.springframework:spring-aop:jar:3.2.8.RELEASE:compile
[INFO] org.springframework:spring-beans:jar:3.2.8.RELEASE:compile
[INFO] org.springframework:spring-context:jar:3.2.8.RELEASE:compile
[INFO] org.springframework:spring-core:jar:3.2.8.RELEASE:compile
[INFO] org.springframework:spring-expression:jar:3.2.8.RELEASE:compile
[INFO] org.springframework:spring-jdbc:jar:3.2.8.RELEASE:compile
[INFO] org.springframework:spring-orm:jar:3.2.8.RELEASE:compile
[INFO] org.springframework:spring-test:jar:2.5.6:compile
[INFO] org.springframework:spring-tx:jar:3.2.8.RELEASE:compile
[INFO] org.springframework.data:spring-data-commons:jar:1.7.1.RELEASE:compile
[INFO] org.springframework.data:spring-data-jpa:jar:1.5.1.RELEASE:compile
[INFO] p6spy:p6spy:jar:2.0.1:test
[INFO] postgresql:postgresql:jar:8.2-507.jdbc3:test
[INFO] taglibs:standard:jar:1.1.2:compile

org.permacode 项目中的所有类都相对简单,这里的整个测试旨在验证应用程序的 Spring 上下文和事务处理的实现和管理,因此该项目中的本地类如 AtomicConfigurationBean 和 ContextManager。除了包装 JPA 实体管理器工厂或 Spring 应用程序上下文之外,它们实际上并没有做任何危险的事情。

我在那里有多个 JPA 提供程序依赖项,因为该项目允许它们之间进行交换 - 这不是一个错误。我认为这不是问题的根源,因为我怀疑 cglib 或其他与代理有关的东西是这里的问题。

昨天,我努力寻找解决方案,筛选了大量关于 BeanCreationException 和 NoClassDefFoundErrors 的求助,但通常受害者的类路径中总是缺少一些可靠的类。在这种情况下,虽然 Spring 提示 $proxy10 ,但我认为它是通过 IOC 配置的一个或另一个 bean 的名称。

我不仅仅是在寻找解决方案,我还会投票或接受关于我应该采取的从头开始解决这个问题的方法的好建议,假设任何顿悟都会迟到。

最佳答案

我认为问题可能与依赖关系的这一部分有关:树:

[INFO]    cglib:cglib:jar:3.1:compile
[INFO] cglib:cglib-nodep:jar:2.1_3:test

在测试范围内(因此在运行测试时),类路径中有两个版本的 cglib,一个是最新的 3.1,另一个是 cglib-nodep,这是一个没有依赖项的 cglib 版本。

尝试在测试范围内升级 cglib-nodep 或在不需要时将其完全删除,或者仅保留 cglib。无论哪种方式,在不同的 jar 中拥有相同类的多个版本都是 NoClassDefFoundError 的常见原因。

关于java - 升级后,在Eclipse中测试通过,在Maven中失败,Spring抛出BeanCreationException/NoClassDefFoundError $proxy10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23090350/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com