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项目的版本号一致,否则会以下报错

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:\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
	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!!

时间: 2024-10-11 19:56:34

junit4 javaee 5.0 jpa SSH 单元测试问题集锦的相关文章

Kali 2.0 采用ssh连接登陆

Kali GNU/Linux 2.0 \n \l 安装完kali2.0 采用ssh远程连接尽然会出现"无法连接"的情况,下面就此情况来解决问题 第一步:编辑ssh配置文件 [email protected]:~# vim /etc/ssh/sshd_config 第二步:重新启动ssh服务 [email protected]:~# /etc/init.d/ssh restart [ ok ] Restarting ssh (via systemctl):ssh.service. 第三步

RHEL7.0修改SSH默认端口及SELinux运行状态修改

Linux系统安装好后,默认会开启SSH服务以便远程配置.但使用默认端口22不安全,一般不建议使用默认端口,那就需要修改SSH默认端口.在RHEL7.0上修改和7.0以下类似,但要注意SELinux的修改. SSH 为 Secure Shell,由IETF的网络工作小组(Network Working Group)所制定:SSH 是建立在应用层和传输层基础上的一种安全协议.SSH传输数据是加密的,可以有效防止传输过程被截取数据保障安全.SSH的数据是经过压缩的,所以可以加快传输的速度. 修改步骤

SSH2.0编程 ssh协议过程实现(转)

之前为了自己做一套SSH,先自己实现了一套telnet.但经过这么多天的苦逼,发现以前的工作都是徒劳.ssh的协议很繁杂,核心的内容在于密码算法,而且自己很难在网上找到周全的细节讲解与详细的实现,只有靠自己刷RFC和问大神还有就是靠强X我的服务器艰难地完成. 现计算了下时间,自己做SSH耗费了进两个月的时间,虽然期间也夹着其他的繁杂事物,但自己在这方面确是是耗费了非常大的精力.因为这方面详细资料的匮乏,自己以前也几乎没有接触过密码学方面的东西,很多只有靠自己摸索,所以我得经常拿我自己的服务器来做

JavaEE学习笔记之SSH—Struts2(1)

现在来学习SSH中的第二个框架--Struts2 Struts2是一个基于MVC设计模式的Web应用框架. 首先将Struts2的框架搭建起来: 1)获取发布包 可以从 Struts2官网.Apache.GitHub等,当然直接百度肯定也是可以的. 2)导入相关 jar 包 将 struts-2.3.24.1-all\struts-2.3.24.1\apps\struts2-blank.war 压缩文件解压,然后将 E:\utils\struts2\struts-2.3.24.1-all\str

VMware Esxi5.1.0开启ssh服务的方法

由于一些原因需要SSH登录进Esxi 5.1.0主机内部修改一些配置,发现ESXI默认是关闭SSH的,以下是在Esxi 5.1.0主机开启SSH服务的方法,供大家和自己参考: 1.先使用Vsphere client登录ESXI: 2.选定你要修改的主机,然后选择"配置",在左边的菜单栏选择"安全配置文件",你可以看到很多服务: 3.然后在"安全配置文件"下的"服务"左边单击"属性": 4.在打开的"

SSH2.0编程 ssh协议过程实现

之前为了自己做一套SSH,先自己实现了一套telnet.但经过这么多天的苦逼,发现以前的工作都是徒劳.ssh的协议很繁杂,核心的内容在于密码算法,而且自己很难在网上找到周全的细节讲解与详细的实现,只有靠自己刷RFC和问大神还有就是靠强X我的服务器艰难地完成. 现计算了下时间,自己做SSH耗费了进两个月的时间,虽然期间也夹着其他的繁杂事物,但自己在这方面确是是耗费了非常大的精力.因为这方面详细资料的匮乏,自己以前也几乎没有接触过密码学方面的东西,很多只有靠自己摸索,所以我得经常拿我自己的服务器来做

JavaEE学习笔记之SSH—Spring(1)

一.Spring相关概念 1:轻量级的容器: 容器:spring容器帮我们管理业务逻辑层,里边有很多业务逻辑对象,有对象就有对象的生命周期的管理(创建,销毁). 轻量级:容器给予的业务逻辑对象多少种服务?spring给用户提供的服务完全由用户自己决定,spring想用什么服务自己开启使用.但是重量级的都是只要你用就把所有的服务都给你,不能自己定制. spring容器从来不能独立运行,一定借助于其他容器启动,或者借助web容器启动,或者ejb容器启动. 特点: 应用模块之间耦合度小,组件都是可重用

centos 7.0 修改ssh默认连接22端口 和 添加防火墙firewalld 通过端口

首先 先做的就是 修改ssh的默认端口22 需要修改文件 /etc/ssh/sshd_config 使用命令 vi /etc/ssh/sshd_config [[email protected] ~]# vi /etc/ssh/sshd_config # $OpenBSD: sshd_config,v 1.90 2013/05/16 04:09:14 dtucker Exp $ # This is the sshd server system-wide configuration file. S

kali2.0 使用SSH进行远程登录

工具/原料 kali 2.0 ssh SSH连接工具(XShell)   一.配置SSH参数 修改sshd_config文件,命令为: vi /etc/ssh/sshd_config 将#PasswordAuthentication no的注释去掉,并且将NO修改为YES //kali中默认是yes 将PermitRootLogin without-password修改为 PermitRootLogin yes 然后,保存,退出vim 二.启动SSH服务 命令为: /etc/init.d/ssh