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

时间:2024-04-13 13:05:55

本篇文章基于已经实现了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. java.lang.IllegalStateException: Failed to load ApplicationContext
  46. at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
  47. at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
  48. at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
  49. at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
  50. at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
  51. at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
  52. at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  53. at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
  54. at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
  55. at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
  56. at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
  57. at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
  58. at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
  59. at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
  60. at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
  61. at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
  62. at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
  63. at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
  64. at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
  65. at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
  66. at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
  67. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
  68. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
  69. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
  70. at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
  71. 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
  72. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
  73. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
  74. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
  75. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
  76. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
  77. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
  78. at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
  79. at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
  80. at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
  81. at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
  82. at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
  83. at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
  84. at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
  85. at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
  86. ... 24 more
  87. 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
  88. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
  89. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
  90. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
  91. at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
  92. at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
  93. at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
  94. at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
  95. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:1136)
  96. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
  97. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
  98. ... 37 more
  99. Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
  100. at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1912)
  101. at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
  102. at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
  103. at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
  104. at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
  105. at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
  106. at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
  107. at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
  108. at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
  109. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
  110. at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
  111. ... 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. <filter>
  7. <filter-name>encodingFilter</filter-name>
  8. <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
  9. <init-param>
  10. <param-name>encoding</param-name>
  11. <param-value>UTF-8</param-value>
  12. </init-param>
  13. <init-param>
  14. <param-name>forceEncoding</param-name>
  15. <param-value>true</param-value>
  16. </init-param>
  17. </filter>
  18. <filter-mapping>
  19. <filter-name>encodingFilter</filter-name>
  20. <url-pattern>/*</url-pattern>
  21. </filter-mapping>
  22. <filter>
  23. <filter-name>struts2</filter-name>
  24. <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  25. </filter>
  26. <filter-mapping>
  27. <filter-name>struts2</filter-name>
  28. <url-pattern>/*</url-pattern>
  29. </filter-mapping>
  30. <filter>
  31. <filter-name>hibernateFilter</filter-name>
  32. <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
  33. <init-param>
  34. <param-name>flushMode</param-name>
  35. <param-value>COMMIT</param-value>
  36. </init-param>
  37. </filter>
  38. <filter-mapping>
  39. <filter-name>hibernateFilter</filter-name>
  40. <url-pattern>/*</url-pattern>
  41. </filter-mapping>
  42. <listener>
  43. <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  44. </listener>
  45. <listener>
  46. <listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>
  47. </listener>
  48. <servlet>
  49. <servlet-name>JspSupportServlet</servlet-name>
  50. <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
  51. <load-on-startup>1</load-on-startup>
  52. </servlet>
  53. <session-config>
  54. <session-timeout>180</session-timeout>
  55. </session-config>
  56. <welcome-file-list>
  57. <welcome-file>/index.jsp</welcome-file>
  58. </welcome-file-list>
  59. </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. <!-- 定义c3p0数据源 -->
  14. <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  15. <property name="hibernateProperties"> <props> <prop key="hibernate.connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</prop>
  16. <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
  17. <prop key="hibernate.cglib.use_reflection_optimizer">true</prop> <prop key="hibernate.proxool.xml">proxool.xml</prop>
  18. <prop key="hibernate.proxool.pool_alias">DBPool</prop> </props> </property>
  19. <property name="mappingResources"> -->
  20. <context:annotation-config />
  21. <!--打开注解模式 -->
  22. <context:component-scan base-package="com.yigo.wqn.*" />
  23. <!--开启自动扫描Bean,一般配到基础包即可。使用这个可以不配置-打开注解模式 -->
  24. <!-- <context:property-placeholder location="classpath:resources.properties"/> -->
  25. <bean
  26. class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  27. <property name="locations">
  28. <list>
  29. <value>classpath:resources.properties</value>
  30. </list>
  31. </property>
  32. </bean>
  33. <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
  34. destroy-method="close">
  35. <!-- 指定连接数据库驱动 -->
  36. <property name="driverClass" value="${db.driver.class.mysql}" />
  37. <!-- 指定连接数据库url -->
  38. <!-- <property name="jdbcUrl" value="jdbc:sqlserver://103.42.176.51:1433;DataBase=ftp4962"
  39. /> -->
  40. <property name="jdbcUrl" value="${db.url.mysql}" />
  41. <!-- 指定连接数据库用户名 -->
  42. <!-- <property name="user" value="ftp4962" /> -->
  43. <property name="user" value="${db.username}" />
  44. <!-- 指定连接数据库密码 -->
  45. <!-- <property name="password" value="ftp4962" /> -->
  46. <property name="password" value="${db.password}" />
  47. </bean>
  48. <!-- 定义Hibernate的sessionFactory -->
  49. <bean id="sessionFactory"
  50. class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  51. <!-- 指定数据源 -->
  52. <property name="dataSource" ref="dataSource" />
  53. <!-- 指定Hibernate映射文件 -->
  54. <!-- <property name="mappingResources"> <list> <value>com/lvche/wqn/domain/Goods.hbm.xml</value>
  55. </list> </property> -->
  56. <!-- 扫描注解信息 -->
  57. <property name="packagesToScan">
  58. <list>
  59. <value>com.yigo.wqn.*</value>
  60. </list>
  61. </property>
  62. <property name="hibernateProperties">
  63. <props>
  64. <!-- 指定使用方言 -->
  65. <prop key="hibernate.dialect">
  66. ${hibernate.dialect.mysql}
  67. </prop>
  68. <!-- 是否在控制台输出sql语句 -->
  69. <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
  70. <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
  71. <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
  72. <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
  73. </props>
  74. </property>
  75. </bean>
  76. <!-- 定义事务管理 -->
  77. <bean id="transactionManager"
  78. class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  79. <property name="sessionFactory" ref="sessionFactory" />
  80. </bean>
  81. <!-- 定义事务管理拦截器 -->
  82. <bean id="transactionInterceptor"
  83. class="org.springframework.transaction.interceptor.TransactionInterceptor">
  84. <property name="transactionManager" ref="transactionManager" />
  85. <property name="transactionAttributes">
  86. <props>
  87. <prop key="get*">
  88. PROPAGATION_REQUIRED,readOnly
  89. </prop>
  90. <prop key="*">PROPAGATION_REQUIRED</prop>
  91. </props>
  92. </property>
  93. </bean>
  94. <!-- 定义代理自动管理事务 -->
  95. <bean id="ProxyCreator"
  96. class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
  97. <!-- 指定需要Spring管理事务的Bean -->
  98. <property name="beanNames">
  99. <list>
  100. <!-- <value>*Service</value>
  101. <value>*ServiceImpl</value> -->
  102. <value>*Dao</value>
  103. <value>*DaoImpl</value>
  104. </list>
  105. </property>
  106. <!-- 调用事务管理拦截器 -->
  107. <property name="interceptorNames">
  108. <list>
  109. <value>transactionInterceptor</value>
  110. </list>
  111. </property>
  112. </bean>
  113. <!-- 依赖注入 -->
  114. <!--dao 层 -->
  115. <!-- <bean id="goodsDao" class="com.lvche.wqn.dao.impl.GoodsDaoImpl">
  116. <property name="sessionFactory" ref="sessionFactory" />
  117. </bean> -->
  118. <!-- action 层 -->
  119. <!-- <bean id="GoodsAction" class="com.lvche.wqn.action.GoodsAction"
  120. scope="prototype">
  121. <property name="goodsDao" ref="goodsDao"></property>
  122. </bean> -->
  123. </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.****.net/wuqilianga/article/details/51295787