After doing a Spring / Hibernate upgrade to the latest versions, I hit problems running my tests under 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
This is my Spring context config:
<?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 is trying to autowire the Spring beans in the context together but falls over while attempting to create either the transaction manager or the transaction proxy manager factory, it's not clear.
I'm using the following dependencies:
[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
All the classes in the org.permacode project are relatively simple and the whole testing here is aimed around validating the application's implementation and management of the Spring context and transaction handling, hence the local classes in this project like AtomicConfigurationBean and ContextManager. These aren't actually doing anything treacherous other than wrapping the JPA entity manager factory or Spring application context.
I have more than one JPA provider dependency in there, because the project allows swapping between them - it's not an error. I assume it's not a source of the problem since I suspect that cglib or something else to do with proxying is the issue here.
I struggled to find a solution to this yesterday, sifting through a great number of cries for help with BeanCreationException and NoClassDefFoundErrors but generally always some solid class was missing from the victim's classpath. In this situation though Spring is complaining about $proxy10 which I assume is meant to be the name of one or other of the beans configured via IOC.
I'm not just looking for a solution, I would also upvote or accept as an answer good advice on an approach I should take to resolve this from scratch, assuming any epiphany will late in coming.