Spring2.5+JUnit4.4做单元测试时遇到这个异常
1903[Thread-3] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory -Retrieved dependent beans for bean 'userDAO':[com.bontade.tests.unit.models.UserDAOTest] 1903[Thread-3] DEBUG org.springframework.beans.factory.support.DefaultListableBeanFactory -Retrieved dependent beans for bean 'userDAO':[com.bontade.tests.unit.models.UserDAOTest] 1904[Thread-3] ERROR org.springframework.beans.factory.support.DefaultListableBeanFactory -Destroy method on bean with name 'userDAO' threw an exception java.lang.ClassFormatError:AbsentCode attribute in method that isnotnativeorabstractinclass file javax/persistence/TransactionRequiredException at java.lang.ClassLoader.defineClass1(NativeMethod) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:632) at java.lang.ClassLoader.defineClass(ClassLoader.java:616) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58) at java.net.URLClassLoader$1.run(URLClassLoader.java:197) at java.security.AccessController.doPrivileged(NativeMethod) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessBeforeDestruction(PersistenceAnnotationBeanPostProcessor.java:339) at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:140) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:487) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:462) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:430) at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:853) at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:831) at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:764)
解决办法:
pom.xml引入一下jar包
<dependency> <groupId>javax.persistence</groupId> <artifactId>persistence-api</artifactId> <version>1.0.2</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax</groupId> <artifactId>javaee-api</artifactId> <version>6.0</version> <scope>provided</scope> <exclusions> <exclusion> <groupId>javax</groupId> <artifactId>javaee-web-api</artifactId> </exclusion> </exclusions> </dependency>
|