本篇文章基于已经实现了ssh集成的demo、项目。具体的ssh项目怎么配置,请参考本文最后
1,下载所需jar包:
spring-test-3.2.0.RELEASE.jar
junit-4.11.jar
commons-dbcp-1.4.jar
junit4测试 和 ssh 集成测试分两种,
一种是比较老点的手动配置
另一种是现在流行的注解扫描配置
先说注解扫描配置集成junit4遇到的坑:
1.下载的spring-test-3.1.2.RELEASE.jar要和自己下载的spring项目的版本号一致,否则会以下报错
- java.lang.IllegalStateException: Could not load TestContextBootstrapper [null]. Specify @BootstrapWith's 'value' attribute or make the default bootstrapper class available.
- at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:160)
- at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:154)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:145)
- at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
- at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
- at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
- at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
- at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
- at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
- at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
- at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
- at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
- at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
- Caused by: java.lang.NoClassDefFoundError: org/springframework/core/annotation/AnnotatedElementUtils
- at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:127)
- ... 21 more
- Caused by: java.lang.ClassNotFoundException: org.springframework.core.annotation.AnnotatedElementUtils
- at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
- at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
- at java.security.AccessController.doPrivileged(Native Method)
- at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
- at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
- ... 22 more
2.junit版本号要再4.9以上,否则也会报错
- java.lang.ExceptionInInitializerError
- at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
- at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
- at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
- at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
- at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:31)
- at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:24)
- at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
- at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:29)
- at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:57)
- at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:24)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
- Caused by: java.lang.IllegalStateException: Failed to find class [org.junit.runners.model.MultipleFailureException]: SpringJUnit4ClassRunner requires JUnit 4.9 or higher.
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<clinit>(SpringJUnit4ClassRunner.java:102)
- ... 18 more
3.
junit4 与 javaee 5.0 jpa包冲突,测试时候屏蔽掉javaee.jar先
- <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.
- at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:160)
- at org.springframework.test.context.TestContextManager.<init>(TestContextManager.java:105)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTestContextManager(SpringJUnit4ClassRunner.java:154)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.<init>(SpringJUnit4ClassRunner.java:145)
- at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
- at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
- at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
- at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
- at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29)
- at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21)
- at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
- at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
- at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
- at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:26)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.<init>(JUnit4TestReference.java:33)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestClassReference.<init>(JUnit4TestClassReference.java:25)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.createTest(JUnit4TestLoader.java:48)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader.loadTests(JUnit4TestLoader.java:38)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:452)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
- Caused by: java.lang.NoClassDefFoundError: org/springframework/core/annotation/AnnotatedElementUtils
- at org.springframework.test.context.BootstrapUtils.resolveTestContextBootstrapper(BootstrapUtils.java:127)
- ... 21 more
- Caused by: java.lang.ClassNotFoundException: org.springframework.core.annotation.AnnotatedElementUtils
- at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
- at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
- at java.security.AccessController.doPrivileged(Native Method)
- at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
- at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
- at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
- ... 22 more</span>
也许你还会遇到诸如spring.xml文件找不着的错误解决方法如下,错误紧接着贴出如下
@ContextConfiguration(locations={"file:WebRoot/WEB-INF/applicationContext.xml"}) //WEB-INF下读取方式
//@ContextConfiguration(locations={"classpath:test/applicationContext.xml"})//类路径下有个test包下
- <span style="font-size:10px;">java.lang.IllegalStateException: Failed to load ApplicationContext
- at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
- at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
- at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
- at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
- at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
- at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
- at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
- at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
- at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
- at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
- at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
- at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
- at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
- at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
- at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
- 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
- at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:341)
- at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
- at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
- at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
- at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
- at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
- at org.springframework.test.context.support.AbstractGenericContextLoader.loadBeanDefinitions(AbstractGenericContextLoader.java:205)
- at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:100)
- at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
- at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
- at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
- at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
- ... 24 more
- Caused by: java.io.FileNotFoundException: class path resource [test/test/applicationContext.xml] cannot be opened because it does not exist
- at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:157)
- at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:328)
- ... 35 more
- java.lang.IllegalStateException: Failed to load ApplicationContext
- at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:157)
- at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)
- at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)
- at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:321)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:211)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:288)
- at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:290)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
- at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
- at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
- at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
- at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
- at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
- at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
- at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
- at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
- at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
- at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
- at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
- at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
- at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
- Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'goodsDao' defined in file [D:wqnmydatajavawebweb_workshop1go(众筹平台)WebRootWEB-INFclassescomyigowqndaoimplGoodsDaoImpl.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
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
- at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
- at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
- at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
- at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
- at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
- at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
- at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
- at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
- ... 24 more
- 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
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
- at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
- at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
- at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
- at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:1136)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
- ... 37 more
- Caused by: java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
- at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1912)
- at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796)
- at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707)
- at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035)
- at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989)
- at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398)
- at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375)
- at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
- at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
- at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
- ... 46 more</span>
配置web.xml:
- <span style="font-size:10px;"><?xml version="1.0" encoding="UTF-8"?>
- <web-app version="3.0"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" metadata-complete="true">
- <filter>
- <filter-name>encodingFilter</filter-name>
- <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
- <init-param>
- <param-name>encoding</param-name>
- <param-value>UTF-8</param-value>
- </init-param>
- <init-param>
- <param-name>forceEncoding</param-name>
- <param-value>true</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>encodingFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <filter>
- <filter-name>struts2</filter-name>
- <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
- </filter>
- <filter-mapping>
- <filter-name>struts2</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <filter>
- <filter-name>hibernateFilter</filter-name>
- <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
- <init-param>
- <param-name>flushMode</param-name>
- <param-value>COMMIT</param-value>
- </init-param>
- </filter>
- <filter-mapping>
- <filter-name>hibernateFilter</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
- <listener>
- <listener-class>org.apache.struts2.dispatcher.ng.listener.StrutsListener</listener-class>
- </listener>
- <servlet>
- <servlet-name>JspSupportServlet</servlet-name>
- <servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class>
- <load-on-startup>1</load-on-startup>
- </servlet>
- <session-config>
- <session-timeout>180</session-timeout>
- </session-config>
- <welcome-file-list>
- <welcome-file>/index.jsp</welcome-file>
- </welcome-file-list>
- </web-app></span>
spring.xml
- <span style="font-size:10px;"><?xml version="1.0" encoding="UTF-8"?>
- <beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xmlns:util="http://www.springframework.org/schema/util"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd
- http://www.springframework.org/schema/util
- http://www.springframework.org/schema/util/spring-util-3.0.xsd"
- default-autowire="byName">
- <!-- 定义c3p0数据源 -->
- <!-- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
- <property name="hibernateProperties"> <props> <prop key="hibernate.connection.provider_class">org.hibernate.connection.ProxoolConnectionProvider</prop>
- <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
- <prop key="hibernate.cglib.use_reflection_optimizer">true</prop> <prop key="hibernate.proxool.xml">proxool.xml</prop>
- <prop key="hibernate.proxool.pool_alias">DBPool</prop> </props> </property>
- <property name="mappingResources"> -->
- <context:annotation-config />
- <!--打开注解模式 -->
- <context:component-scan base-package="com.yigo.wqn.*" />
- <!--开启自动扫描Bean,一般配到基础包即可。使用这个可以不配置-打开注解模式 -->
- <!-- <context:property-placeholder location="classpath:resources.properties"/> -->
- <bean
- class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="locations">
- <list>
- <value>classpath:resources.properties</value>
- </list>
- </property>
- </bean>
- <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
- destroy-method="close">
- <!-- 指定连接数据库驱动 -->
- <property name="driverClass" value="${db.driver.class.mysql}" />
- <!-- 指定连接数据库url -->
- <!-- <property name="jdbcUrl" value="jdbc:sqlserver://103.42.176.51:1433;DataBase=ftp4962"
- /> -->
- <property name="jdbcUrl" value="${db.url.mysql}" />
- <!-- 指定连接数据库用户名 -->
- <!-- <property name="user" value="ftp4962" /> -->
- <property name="user" value="${db.username}" />
- <!-- 指定连接数据库密码 -->
- <!-- <property name="password" value="ftp4962" /> -->
- <property name="password" value="${db.password}" />
- </bean>
- <!-- 定义Hibernate的sessionFactory -->
- <bean id="sessionFactory"
- class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
- <!-- 指定数据源 -->
- <property name="dataSource" ref="dataSource" />
- <!-- 指定Hibernate映射文件 -->
- <!-- <property name="mappingResources"> <list> <value>com/lvche/wqn/domain/Goods.hbm.xml</value>
- </list> </property> -->
- <!-- 扫描注解信息 -->
- <property name="packagesToScan">
- <list>
- <value>com.yigo.wqn.*</value>
- </list>
- </property>
- <property name="hibernateProperties">
- <props>
- <!-- 指定使用方言 -->
- <prop key="hibernate.dialect">
- ${hibernate.dialect.mysql}
- </prop>
- <!-- 是否在控制台输出sql语句 -->
- <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
- <prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
- <prop key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
- <prop key="hibernate.format_sql">${hibernate.format_sql}</prop>
- </props>
- </property>
- </bean>
- <!-- 定义事务管理 -->
- <bean id="transactionManager"
- class="org.springframework.orm.hibernate3.HibernateTransactionManager">
- <property name="sessionFactory" ref="sessionFactory" />
- </bean>
- <!-- 定义事务管理拦截器 -->
- <bean id="transactionInterceptor"
- class="org.springframework.transaction.interceptor.TransactionInterceptor">
- <property name="transactionManager" ref="transactionManager" />
- <property name="transactionAttributes">
- <props>
- <prop key="get*">
- PROPAGATION_REQUIRED,readOnly
- </prop>
- <prop key="*">PROPAGATION_REQUIRED</prop>
- </props>
- </property>
- </bean>
- <!-- 定义代理自动管理事务 -->
- <bean id="ProxyCreator"
- class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
- <!-- 指定需要Spring管理事务的Bean -->
- <property name="beanNames">
- <list>
- <!-- <value>*Service</value>
- <value>*ServiceImpl</value> -->
- <value>*Dao</value>
- <value>*DaoImpl</value>
- </list>
- </property>
- <!-- 调用事务管理拦截器 -->
- <property name="interceptorNames">
- <list>
- <value>transactionInterceptor</value>
- </list>
- </property>
- </bean>
- <!-- 依赖注入 -->
- <!--dao 层 -->
- <!-- <bean id="goodsDao" class="com.lvche.wqn.dao.impl.GoodsDaoImpl">
- <property name="sessionFactory" ref="sessionFactory" />
- </bean> -->
- <!-- action 层 -->
- <!-- <bean id="GoodsAction" class="com.lvche.wqn.action.GoodsAction"
- scope="prototype">
- <property name="goodsDao" ref="goodsDao"></property>
- </bean> -->
- </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