Fight With Me!!!

导航

junit4 javaee 5.0 jpa SSH 单元测试问题集锦

本篇文章基于已经实现了ssh集成的demo、项目。具体的ssh项目怎么配置,请参考本文最后

spring环境下的JUnit4测试

1,下载所需jar包:

spring-test-3.2.0.RELEASE.jar

junit-4.11.jar

commons-dbcp-1.4.jar

jar包怎么下载?

junit4测试 和 ssh 集成测试分两种,

一种是比较老点的手动配置

另一种是现在流行的注解扫描配置

先说注解扫描配置集成junit4遇到的坑:

1.下载的\spring-test-3.1.2.RELEASE.jar要和自己下载的spring项目的版本号一致,否则会以下报错

  1. java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available.  
  2.     at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:160)  
  3.     at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105)  
  4.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:154)  
  5.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:145)  
  6.     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
  7.     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)  
  8.     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)  
  9.     at java.lang.reflect.Constructor.newInstance(Constructor.java:526)  
  10.     at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)  
  11.     at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)  
  12.     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)  
  13.     at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)  
  14.     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)  
  15.     at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)  
  16.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)  
  17.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)  
  18.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)  
  19.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)  
  20.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)  
  21.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)  
  22.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)  
  23.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)  
  24. Caused by: java.lang.NoClassDefFoundError: org/springframework/core/annotation/AnnotatedElementUtils  
  25.     at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:127)  
  26.     ... 21 more  
  27. Caused by: java.lang.ClassNotFoundException: org.springframework.core.annotation.AnnotatedElementUtils  
  28.     at java.net.URLClassLoader$1.run(URLClassLoader.java:366)  
  29.     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)  
  30.     at java.security.AccessController.doPrivileged(Native Method)  
  31.     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)  
  32.     at java.lang.ClassLoader.loadClass(ClassLoader.java:425)  
  33.     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)  
  34.     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)  
  35.     ... 22 more  

 

2.junit版本号要再4.9以上,否则也会报错

  1. java.lang.ExceptionInInitializerError  
  2.     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
  3.     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)  
  4.     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)  
  5.     at java.lang.reflect.Constructor.newInstance(Constructor.java:526)  
  6.     at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)  
  7.     at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)  
  8.     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)  
  9.     at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)  
  10.     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)  
  11.     at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)  
  12.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)  
  13.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)  
  14.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)  
  15.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)  
  16.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)  
  17.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)  
  18.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)  
  19.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)  
  20. Caused by: java.lang.IllegalStateException: Failed to find class [org.junit.runners.model.MultipleFailureException]: SpringJUnit4ClassRunner requires JUnit 4.9 or higher.  
  21.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<clinit>(SpringJUnit4ClassRunner.java:102)  
  22.     ... 18 more  


3. 

junit4 与 javaee 5.0 jpa包冲突,测试时候屏蔽掉javaee.jar先


  1. <span style="font-size:12px;">java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available.  
  2.     at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:160)  
  3.     at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105)  
  4.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:154)  
  5.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:145)  
  6.     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
  7.     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)  
  8.     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)  
  9.     at java.lang.reflect.Constructor.newInstance(Constructor.java:526)  
  10.     at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)  
  11.     at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)  
  12.     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)  
  13.     at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)  
  14.     at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)  
  15.     at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)  
  16.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)  
  17.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)  
  18.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)  
  19.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)  
  20.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)  
  21.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)  
  22.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)  
  23.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)  
  24. Caused by: java.lang.NoClassDefFoundError: org/springframework/core/annotation/AnnotatedElementUtils  
  25.     at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:127)  
  26.     ... 21 more  
  27. Caused by: java.lang.ClassNotFoundException: org.springframework.core.annotation.AnnotatedElementUtils  
  28.     at java.net.URLClassLoader$1.run(URLClassLoader.java:366)  
  29.     at java.net.URLClassLoader$1.run(URLClassLoader.java:355)  
  30.     at java.security.AccessController.doPrivileged(Native Method)  
  31.     at java.net.URLClassLoader.findClass(URLClassLoader.java:354)  
  32.     at java.lang.ClassLoader.loadClass(ClassLoader.java:425)  
  33.     at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)  
  34.     at java.lang.ClassLoader.loadClass(ClassLoader.java:358)  
  35.     ... 22 more</span>  

也许你还会遇到诸如spring.xml文件找不着的错误解决方法如下,错误紧接着贴出如下

@ContextConfiguration(locations={"file:WebRoot/WEB-INF/applicationContext.xml"}) //WEB-INF下读取方式

//@ContextConfiguration(locations={"classpath:test/applicationContext.xml"})//类路径下有个test包下

  1. <span style="font-size:10px;">java.lang.IllegalStateException: Failed to load ApplicationContext  
  2.     at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)  
  3.     at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)  
  4.     at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)  
  5.     at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)  
  6.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)  
  7.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)  
  8.     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)  
  9.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)  
  10.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)  
  11.     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)  
  12.     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)  
  13.     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)  
  14.     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)  
  15.     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)  
  16.     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)  
  17.     at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)  
  18.     at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)  
  19.     at org.junit.runners.ParentRunner.run(ParentRunner.java:309)  
  20.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)  
  21.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)  
  22.     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)  
  23.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)  
  24.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)  
  25.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)  
  26.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)  
  27. Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [test/test/applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [test/test/applicationContext.xml] cannot be opened because it does not exist  
  28.     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)  
  29.     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)  
  30.     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)  
  31.     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)  
  32.     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)  
  33.     at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)  
  34.     at org.springframework.test.context.support.AbstractGenericContextLoader.loadBeanDefinitions(AbstractGenericContextLoader.java:205)  
  35.     at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:100)  
  36.     at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)  
  37.     at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)  
  38.     at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)  
  39.     at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)  
  40.     ... 24 more  
  41. Caused by: java.io.FileNotFoundException: class path resource [test/test/applicationContext.xml] cannot be opened because it does not exist  
  42.     at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)  
  43.     at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)  
  44.     ... 35 more  
  45.   
  46.   
  47.   
  48.   
  49.   
  50. java.lang.IllegalStateException: Failed to load ApplicationContext  
  51.     at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)  
  52.     at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)  
  53.     at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)  
  54.     at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)  
  55.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)  
  56.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)  
  57.     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)  
  58.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)  
  59.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)  
  60.     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)  
  61.     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)  
  62.     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)  
  63.     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)  
  64.     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)  
  65.     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)  
  66.     at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)  
  67.     at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)  
  68.     at org.junit.runners.ParentRunner.run(ParentRunner.java:309)  
  69.     at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)  
  70.     at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)  
  71.     at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)  
  72.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)  
  73.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)  
  74.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)  
  75.     at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)  
  76. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'goodsDao' defined in file [D:\wqn\mydata\javaweb\web_workshop\1go(众筹平台)\WebRoot\WEB-INF\classes\com\yigo\wqn\dao\impl\GoodsDaoImpl.class]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z  
  77.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)  
  78.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)  
  79.     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)  
  80.     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)  
  81.     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)  
  82.     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)  
  83.     at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)  
  84.     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)  
  85.     at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)  
  86.     at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)  
  87.     at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)  
  88.     at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)  
  89.     at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)  
  90.     at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)  
  91.     ... 24 more  
  92. Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z  
  93.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)  
  94.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)  
  95.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)  
  96.     at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)  
  97.     at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)  
  98.     at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)  
  99.     at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)  
  100.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:1136)  
  101.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)  
  102.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)  
  103.     ... 37 more  
  104. Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z  
  105.     at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1912)  
  106.     at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)  
  107.     at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)  
  108.     at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)  
  109.     at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)  
  110.     at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)  
  111.     at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)  
  112.     at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)  
  113.     at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)  
  114.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)  
  115.     at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)  
  116.     ... 46 more</span>  


配置web.xml:

  1. <span style="font-size:10px;"><?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app version="3.0"   
  3.         xmlns="http://java.sun.com/xml/ns/javaee"   
  4.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
  5.         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="true">  
  6.           
  7.     <filter>  
  8.         <filter-name>encodingFilter</filter-name>  
  9.         <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>  
  10.         <init-param>  
  11.             <param-name>encoding</param-name>  
  12.             <param-value>UTF-8</param-value>  
  13.         </init-param>  
  14.         <init-param>  
  15.             <param-name>forceEncoding</param-name>  
  16.             <param-value>true</param-value>  
  17.         </init-param>  
  18.     </filter>  
  19.     <filter-mapping>  
  20.         <filter-name>encodingFilter</filter-name>  
  21.         <url-pattern>/*</url-pattern>  
  22.     </filter-mapping>  
  23.     
  24.     <filter>  
  25.         <filter-name>struts2</filter-name>  
  26.         <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>  
  27.     </filter>  
  28.     <filter-mapping>  
  29.         <filter-name>struts2</filter-name>  
  30.         <url-pattern>/*</url-pattern>  
  31.     </filter-mapping>  
  32.       
  33.     <filter>  
  34.         <filter-name>hibernateFilter</filter-name>  
  35.         <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>  
  36.         <init-param>  
  37.             <param-name>flushMode</param-name>  
  38.             <param-value>COMMIT</param-value>  
  39.         </init-param>  
  40.     </filter>  
  41.     <filter-mapping>  
  42.         <filter-name>hibernateFilter</filter-name>  
  43.         <url-pattern>/*</url-pattern>  
  44.     </filter-mapping>  
  45.       
  46.     <listener>  
  47.         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>  
  48.     </listener>  
  49.   
  50.     <listener>  
  51.         <listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>  
  52.     </listener>  
  53.     
  54.     <servlet>  
  55.         <servlet-name>JspSupportServlet</servlet-name>  
  56.         <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>  
  57.         <load-on-startup>1</load-on-startup>  
  58.     </servlet>  
  59.     
  60.     <session-config>  
  61.         <session-timeout>180</session-timeout>  
  62.     </session-config>  
  63.     
  64.     <welcome-file-list>  
  65.         <welcome-file>/index.jsp</welcome-file>  
  66.     </welcome-file-list>  
  67. </web-app></span>  


spring.xml

  1. <span style="font-size:10px;"><?xml version="1.0" encoding="UTF-8"?>  
  2. <beans xmlns="http://www.springframework.org/schema/beans"  
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xmlns:context="http://www.springframework.org/schema/context"  
  5.     xmlns:util="http://www.springframework.org/schema/util"  
  6.     xsi:schemaLocation="http://www.springframework.org/schema/beans   
  7.     http://www.springframework.org/schema/beans/spring-beans-3.0.xsd   
  8.     http://www.springframework.org/schema/context   
  9.     http://www.springframework.org/schema/context/spring-context-3.0.xsd   
  10.     http://www.springframework.org/schema/util   
  11.     http://www.springframework.org/schema/util/spring-util-3.0.xsd"  
  12.     default-autowire="byName">  
  13.   
  14.     <!-- 定义c3p0数据源 -->  
  15.     <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">   
  16.         <property name="hibernateProperties"<props<prop key="hibernate.connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</prop>   
  17.         <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>   
  18.         <prop key="hibernate.cglib.use_reflection_optimizer">true</prop<prop key="hibernate.proxool.xml">proxool.xml</prop>   
  19.         <prop key="hibernate.proxool.pool_alias">DBPool</prop</props</property>   
  20.         <property name="mappingResources"> -->  
  21.   
  22.     <context:annotation-config />   
  23.       
  24.     <!--打开注解模式 -->  
  25.     <context:component-scan base-package="com.yigo.wqn.*" />  
  26.     <!--开启自动扫描Bean,一般配到基础包即可。使用这个可以不配置-打开注解模式 -->  
  27.     <!-- <context:property-placeholder location="classpath:resources.properties"/> -->  
  28.   
  29.     <bean  
  30.         class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">  
  31.         <property name="locations">  
  32.             <list>  
  33.                 <value>classpath:resources.properties</value>  
  34.             </list>  
  35.         </property>  
  36.     </bean>  
  37.   
  38.     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"  
  39.         destroy-method="close">  
  40.         <!-- 指定连接数据库驱动 -->  
  41.         <property name="driverClass" value="${db.driver.class.mysql}" />  
  42.         <!-- 指定连接数据库url -->  
  43.         <!-- <property name="jdbcUrl" value="jdbc:sqlserver://103.42.176.51:1433;DataBase=ftp4962"   
  44.             /> -->  
  45.         <property name="jdbcUrl" value="${db.url.mysql}" />  
  46.         <!-- 指定连接数据库用户名 -->  
  47.         <!-- <property name="user" value="ftp4962" /> -->  
  48.         <property name="user" value="${db.username}" />  
  49.         <!-- 指定连接数据库密码 -->  
  50.         <!-- <property name="password" value="ftp4962" /> -->  
  51.         <property name="password" value="${db.password}" />  
  52.     </bean>  
  53.     <!-- 定义Hibernate的sessionFactory -->  
  54.     <bean id="sessionFactory"  
  55.         class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">  
  56.         <!-- 指定数据源 -->  
  57.         <property name="dataSource" ref="dataSource" />  
  58.         <!-- 指定Hibernate映射文件 -->  
  59.         <!-- <property name="mappingResources"<list<value>com/lvche/wqn/domain/Goods.hbm.xml</value>   
  60.             </list</property> -->  
  61.               
  62.         <!-- 扫描注解信息 -->  
  63.         <property name="packagesToScan">  
  64.             <list>  
  65.                 <value>com.yigo.wqn.*</value>  
  66.             </list>  
  67.         </property>  
  68.   
  69.         <property name="hibernateProperties">  
  70.             <props>  
  71.                 <!-- 指定使用方言 -->  
  72.                 <prop key="hibernate.dialect">  
  73.                     ${hibernate.dialect.mysql}  
  74.                 </prop>  
  75.                 <!-- 是否在控制台输出sql语句 -->  
  76.                 <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>  
  77.                 <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>  
  78.                 <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>  
  79.                 <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>  
  80.             </props>  
  81.         </property>  
  82.     </bean>  
  83.     <!-- 定义事务管理 -->  
  84.     <bean id="transactionManager"  
  85.         class="org.springframework.orm.hibernate3.HibernateTransactionManager">  
  86.         <property name="sessionFactory" ref="sessionFactory" />  
  87.     </bean>  
  88.     <!-- 定义事务管理拦截器 -->  
  89.     <bean id="transactionInterceptor"  
  90.         class="org.springframework.transaction.interceptor.TransactionInterceptor">  
  91.         <property name="transactionManager" ref="transactionManager" />  
  92.         <property name="transactionAttributes">  
  93.             <props>  
  94.                 <prop key="get*">  
  95.                     PROPAGATION_REQUIRED,readOnly  
  96.                 </prop>  
  97.                 <prop key="*">PROPAGATION_REQUIRED</prop>  
  98.             </props>  
  99.         </property>  
  100.     </bean>  
  101.     <!-- 定义代理自动管理事务 -->  
  102.     <bean id="ProxyCreator"  
  103.         class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">  
  104.         <!-- 指定需要Spring管理事务的Bean -->  
  105.         <property name="beanNames">  
  106.             <list>  
  107.                 <!-- <value>*Service</value>  
  108.                 <value>*ServiceImpl</value> -->  
  109.                 <value>*Dao</value>  
  110.                 <value>*DaoImpl</value>  
  111.             </list>  
  112.         </property>  
  113.         <!-- 调用事务管理拦截器 -->  
  114.         <property name="interceptorNames">  
  115.             <list>  
  116.                 <value>transactionInterceptor</value>  
  117.             </list>  
  118.         </property>  
  119.     </bean>  
  120.     <!-- 依赖注入 -->  
  121.     <!--dao 层 -->  
  122.     <!-- <bean id="goodsDao" class="com.lvche.wqn.dao.impl.GoodsDaoImpl">  
  123.         <property name="sessionFactory" ref="sessionFactory" />  
  124.     </bean> -->  
  125.     <!-- action 层 -->  
  126.     <!-- <bean id="GoodsAction" class="com.lvche.wqn.action.GoodsAction"  
  127.         scope="prototype">  
  128.         <property name="goodsDao" ref="goodsDao"></property>  
  129.     </bean> -->  
  130. </beans></span>  


Lib list:

activation-1.0.2.jar
ant-1.7.1.jar
antlr-2.7.6.jar
aopalliance-1.0.jar
asm-3.3.jar
asm-commons-3.3.jar
asm-tree-3.3.jar
asm-util-3.2.jar
aspectjrt-1.6.10.jar
aspectjweaver-1.6.10.jar
bsh-1.3.0.jar
c3p0-0.9.1.2.jar
carol-2.0.5.jar
cglib-2.2.2.jar
cglib-nodep-2.2.jar
commons-beanutils-1.8.0.jar
commons-beanutils-core-1.8.0.jar
commons-chain-1.2.jar
commons-codec-1.3.jar
commons-collections-3.2.1.jar
commons-dbcp-1.4.jar
commons-digester-2.1.jar
commons-el-1.0.jar
commons-fileupload-1.2.2.jar
commons-httpclient-3.1.jar
commons-io-2.0.1.jar
commons-lang-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
commons-logging-api-1.1.jar
commons-modeler-2.0.jar
commons-pool-1.5.4.jar
commons-validator-1.3.1.jar
concurrent-1.3.4.jar
connector-1.0.jar
dom4j-1.6.1.jar
dwr-1.1.1.jar
ehcache-1.2.3.jar
freemarker-2.3.19.jar
groovy-all-2.0.1.jar
hibernate-jpa-2.0-api-1.0.1.Final.jar
hibernate3-3.6.10.Final.jar
howl-logger-0.1.11.jar
javassist-3.12.1.GA.jar
jcommon-1.0.15.jar
jdom-1.0.jar
jgroups-all-2.4.1.jar
jms-1.1.jar
jmxri-1.2.jar
jmxtools-1.2.jar
jotm_jrmp_stubs-2.0.10.jar
jotm-2.0.10.jar
jsf-api-1.2_04.jar
jsf-impl-1.2_04.jar
jstl-1.2.jar
jta-1.1.jar
junit-4.11.jar
junit-4.8.2.jar
jxl-2.6.10.jar
log4j-1.2.16.jar
mail-1.3.3.jar
mx4j-jmx-2.1.1.jar
mysql-connector-java-5.1.22-bin.jar
ognl-3.0.6.jar
org.springframework.aop-3.1.2.RELEASE.jar
org.springframework.asm-3.1.2.RELEASE.jar
org.springframework.aspects-3.1.2.RELEASE.jar
org.springframework.beans-3.1.2.RELEASE.jar
org.springframework.context-3.1.2.RELEASE.jar
org.springframework.context.support-3.1.2.RELEASE.jar
org.springframework.core-3.1.2.RELEASE.jar
org.springframework.expression-3.1.2.RELEASE.jar
org.springframework.instrument-3.1.2.RELEASE.jar
org.springframework.instrument.tomcat-3.1.2.RELEASE.jar
org.springframework.jdbc-3.1.2.RELEASE.jar
org.springframework.orm-3.1.2.RELEASE.jar
org.springframework.transaction-3.1.2.RELEASE.jar
org.springframework.web-3.1.2.RELEASE.jar
org.springframework.web.servlet-3.1.2.RELEASE.jar
org.springframework.web.struts-3.1.2.RELEASE.jar
oro-2.0.8.jar
proxool-0.8.3.jar
qdox-1.5.jar
rife-continuations-0.0.2.jar
slf4j-api-1.6.1.jar
slf4j-log4j12-1.6.1.jar
slf4j-simple-1.6.1.jar
spring-test-3.1.2.RELEASE.jar
struts2-config-browser-plugin-2.3.15.1.jar
struts2-convention-plugin-2.3.15.1.jar
struts2-core-2.3.15.1.jar
struts2-dojo-plugin-2.3.15.1.jar
struts2-spring-plugin-2.3.15.1.jar
swarmcache-1.0RC2.jar
transmorph-3.1.1.jar
xapool-1.5.0.jar
xml-apis-1.0.b2.jar
xwork-core-2.3.15.1.jar

~~~~~~~~~~~~end!!

 

转自:http://blog.csdn.net/wuqilianga/article/details/51295787

posted on 2016-11-29 14:05  nickTimer  阅读(369)  评论(0编辑  收藏  举报