无法加载HIbernate+;H2内存数据库,用于使用Spring和Maven自动化测试

无法加载HIbernate+;H2内存数据库,用于使用Spring和Maven自动化测试,spring,hibernate,maven,testing,h2,Spring,Hibernate,Maven,Testing,H2,您好,我有一个Spring应用程序,在内存DB和JAX-RS中使用Hibernate+H2。 我试图创建单元测试来测试DB操作 我的配置: OrderDaoTest:(证明配置的简单类) package com.ac.test.dataaccess; 导入com.ac.dataaccess.OrderDao; 导入com.ac.entities.Order; 导入org.junit.Test; 导入org.junit.runner.RunWith; 导入org.springframework.b

您好,我有一个Spring应用程序,在内存DB和JAX-RS中使用Hibernate+H2。 我试图创建单元测试来测试DB操作

我的配置: OrderDaoTest:(证明配置的简单类)

package com.ac.test.dataaccess;
导入com.ac.dataaccess.OrderDao;
导入com.ac.entities.Order;
导入org.junit.Test;
导入org.junit.runner.RunWith;
导入org.springframework.beans.factory.annotation.Autowired;
导入org.springframework.test.context.ContextConfiguration;
导入org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
导入java.util.List;
/**
*由罗穆塔于2015年2月21日创建。
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(位置={“类路径:/dataSourceContext.xml”,“类路径:/applicationContext.xml”})
公共类测试{
@自动连线
私有OrderDao OrderDao;
@试验
公共void测试列表(){
List List=orderDao.List();
}
}
dataSourceContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="testDS" />
        <property name="resourceRef" value="true"/>
        <property name="lookupOnStartup" value="false"/>
        <property name="proxyInterface" value="javax.sql.DataSource"/>
        <property name="cache" value="false"/>
    </bean>

</beans>
<?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:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd" default-autowire="byName" default-autowire-candidates="*" >

    <tx:annotation-driven/>
    <bean id="orderDao" class="com.ac.dataaccess.OrderDao"/>
    <bean id="productDaoDao" class="com.ac.dataaccess.ProductDao"/>

    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="mappingResources">
            <list>
                <value>hibernate.hbm.xml</value>
            </list>
        </property>
        <property name="dataSource" ref="dataSource"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
                <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
                <prop key="hibernate.connection.url">jdbc:h2:~/acdb</prop>
                <prop key="hibernate.connection.isolation">2</prop>
                <prop key="hibernate.connection.autocommit">true</prop>
                <prop key="hibernate.generate_statistics">true</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.use_sql_comments">true</prop>
                <prop key="hibernate.jdbc.fetch_size">100</prop>
                <prop key="hibernate.jdbc.batch_size">30</prop>
                <prop key="hibernate.order_inserts">true</prop>
                <prop key="hibernate.order_updates">true</prop>
                <prop key="hibernate.max_fetch_depth">3</prop>
                <prop key="hibernate.hbm2ddl.import_files">import.sql</prop>
            </props>
        </property>
    </bean>

</beans>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">

    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="testDS" />
        <property name="resourceRef" value="true"/>
        <property name="lookupOnStartup" value="false"/>
        <property name="proxyInterface" value="javax.sql.DataSource"/>
        <property name="cache" value="false"/>
    </bean>

</beans>
<?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:tx="http://www.springframework.org/schema/tx"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd" default-autowire="byName" default-autowire-candidates="*" >

    <tx:annotation-driven/>
    <bean id="orderDao" class="com.ac.dataaccess.OrderDao"/>
    <bean id="productDaoDao" class="com.ac.dataaccess.ProductDao"/>

    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory"/>
    </bean>

    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="mappingResources">
            <list>
                <value>hibernate.hbm.xml</value>
            </list>
        </property>
        <property name="dataSource" ref="dataSource"/>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
                <prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</prop>
                <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
                <prop key="hibernate.connection.url">jdbc:h2:~/acdb</prop>
                <prop key="hibernate.connection.isolation">2</prop>
                <prop key="hibernate.connection.autocommit">true</prop>
                <prop key="hibernate.generate_statistics">true</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.format_sql">true</prop>
                <prop key="hibernate.use_sql_comments">true</prop>
                <prop key="hibernate.jdbc.fetch_size">100</prop>
                <prop key="hibernate.jdbc.batch_size">30</prop>
                <prop key="hibernate.order_inserts">true</prop>
                <prop key="hibernate.order_updates">true</prop>
                <prop key="hibernate.max_fetch_depth">3</prop>
                <prop key="hibernate.hbm2ddl.import_files">import.sql</prop>
            </props>
        </property>
    </bean>

</beans>

hibernate.hbm.xml
创造
org.hibernate.transaction.jdbc事务工厂
org.hibernate.dial.h2方言
jdbc:h2:~/acdb
2.
真的
真的
真的
真的
真的
100
30
真的
真的
3.
import.sql
运行mvn测试时,我得到以下错误:

romurta@romurta-server:~/IdeaProjects/ac-recruitment-java-challenge$ mvn test
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building java-webapp-coding-test 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) @ java-webapp-coding-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 9 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ java-webapp-coding-test ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.3:testResources (default-testResources) @ java-webapp-coding-test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /home/romurta/IdeaProjects/ac-recruitment-java-challenge/src/test/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ java-webapp-coding-test ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /home/romurta/IdeaProjects/ac-recruitment-java-challenge/target/test-classes
[INFO] 
[INFO] --- maven-surefire-plugin:2.10:test (default-test) @ java-webapp-coding-test ---
[INFO] Surefire report directory: /home/romurta/IdeaProjects/ac-recruitment-java-challenge/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running com.ac.test.dataaccess.OrderDaoTest
2015-02-21 23:04:22.472 [main] INFO  org.springframework.test.context.TestContextManager - Could not instantiate TestExecutionListener class [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their dependencies) available.
2015-02-21 23:04:23.048 [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [dataSourceContext.xml]
2015-02-21 23:04:23.388 [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [applicationContext.xml]
2015-02-21 23:04:26.380 [main] ERROR org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@42de5b73] to prepare test instance [com.ac.test.dataaccess.OrderDaoTest@1445fd51]
java.lang.IllegalStateException: Failed to load ApplicationContext
        at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99) ~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101) ~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109) ~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75) ~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:324) ~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:290) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) [junit-4.11.jar:na]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:292) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) [junit-4.11.jar:na]
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) [junit-4.11.jar:na]
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) [junit-4.11.jar:na]
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) [junit-4.11.jar:na]
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) [junit-4.11.jar:na]
        at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.junit.runners.ParentRunner.run(ParentRunner.java:309) [junit-4.11.jar:na]
        at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176) [spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:53) [surefire-junit4-2.10.jar:2.10]
        at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:123) [surefire-junit4-2.10.jar:2.10]
        at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:104) [surefire-junit4-2.10.jar:2.10]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_76]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_76]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_76]
        at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_76]
        at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:164) [surefire-api-2.10.jar:2.10]
        at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:110) [surefire-booter-2.10.jar:2.10]
        at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(SurefireStarter.java:175) [surefire-booter-2.10.jar:2.10]
        at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(SurefireStarter.java:107) [surefire-booter-2.10.jar:2.10]
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:68) [surefire-booter-2.10.jar:2.10]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderDao' defined in class path resource [applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; 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 org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:547) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[spring-context-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125) ~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60) ~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:100) ~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:250) ~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64) ~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91) ~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        ... 31 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; 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 org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1456) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1197) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByName(AbstractAutowireCapableBeanFactory.java:1215) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1165) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        ... 45 common frames omitted
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 org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        ... 57 common frames omitted
Caused by: org.springframework.jndi.JndiLookupFailureException: JndiObjectTargetSource failed to obtain new target object; nested exception is javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at org.springframework.jndi.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:142) ~[spring-context-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:187) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at com.sun.proxy.$Proxy10.getConnection(Unknown Source) ~[na:na]
        at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:139) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcServicesImpl.java:279) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
        at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:124) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:111) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:234) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:206) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
        at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
        at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1928) ~[hibernate-core-4.3.5.Final.jar:4.3.5.Final]
        at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:343) ~[spring-orm-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:431) ~[spring-orm-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:416) ~[spring-orm-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[spring-beans-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        ... 64 common frames omitted
Caused by: javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) ~[na:1.7.0_76]
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) ~[na:1.7.0_76]
        at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344) ~[na:1.7.0_76]
        at javax.naming.InitialContext.lookup(InitialContext.java:411) ~[na:1.7.0_76]
        at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:155) ~[spring-context-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87) ~[spring-context-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152) ~[spring-context-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:179) ~[spring-context-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:104) ~[spring-context-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:106) ~[spring-context-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        at org.springframework.jndi.JndiObjectTargetSource.getTarget(JndiObjectTargetSource.java:130) ~[spring-context-4.0.4.RELEASE.jar:4.0.4.RELEASE]
        ... 80 common frames omitted
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 5.419 sec <<< FAILURE!

Results :

Tests in error: 
  testList(com.ac.test.dataaccess.OrderDaoTest): Failed to load ApplicationContext

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 16.987s
[INFO] Finished at: Sat Feb 21 23:04:26 BRT 2015
[INFO] Final Memory: 21M/154M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.10:test (default-test) on project java-webapp-coding-test: There are test failures.
[ERROR] 
[ERROR] Please refer to /home/romurta/IdeaProjects/ac-recruitment-java-challenge/target/surefire-reports for the individual test results.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
romurta@romurta-服务器:~/IdeaProjects/ac招聘java挑战$mvn测试
[信息]正在扫描项目。。。
[信息]
[信息]------------------------------------------------------------------------
[信息]构建java webapp编码测试0.0.1-SNAPSHOT
[信息]------------------------------------------------------------------------
[信息]
[信息]---maven资源插件:2.3:resources(默认资源)@JavaWebApp编码测试---
[信息]使用“UTF-8”编码复制筛选的资源。
[信息]正在复制9个资源
[信息]
[信息]---maven编译器插件:3.1:compile(默认编译)@JavaWebApp编码测试---
[信息]无需编译-所有类都是最新的
[信息]
[信息]---maven资源插件:2.3:testResources(默认testResources)@JavaWebApp编码测试---
[信息]使用“UTF-8”编码复制筛选的资源。
[信息]跳过不存在的resourceDirectory/home/romurta/IdeaProjects/ac招聘java challenge/src/test/resources
[信息]
[信息]---maven编译器插件:3.1:testCompile(默认testCompile)@JavaWebApp编码测试---
[信息]检测到更改-重新编译模块!
[信息]将1个源文件编译到/home/romurta/IdeaProjects/ac招聘java挑战/目标/测试类
[信息]
[信息]---maven surefire插件:2.10:test(默认测试)@JavaWebApp编码测试---
[信息]Surefire报告目录:/home/romurta/IdeaProjects/ac招聘java挑战/target/Surefire报告
-------------------------------------------------------
T T S T S
-------------------------------------------------------
正在运行com.ac.test.dataaccess.OrderDaoTest
2015-02-21 23:04:22.472[main]INFO org.springframework.test.context.TestContextManager-无法实例化TestExecutionListener类[org.springframework.test.context.web.ServletTestExecutionListener]。指定自定义侦听器类或使默认侦听器类(及其依赖项)可用。
2015-02-21 23:04:23.048[main]INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader-从类路径资源[dataSourceContext.xml]加载xml bean定义
2015-02-21 23:04:23.388[main]INFO org.springframework.beans.factory.xml.XmlBeanDefinitionReader-从类路径资源[applicationContext.xml]加载xml bean定义
2015-02-21 23:04:26.380[main]错误org.springframework.test.context.TestContextManager-允许TestExecutionListener[org.springframework.test.context.support]时捕获异常。DependencyInjectionTestExecutionListener@42de5b73]准备测试实例[com.ac.test.dataaccess]。OrderDaoTest@1445fd51]
java.lang.IllegalStateException:未能加载ApplicationContext
在org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
在org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:101)~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
在org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:109)~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
在org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:75)~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
在org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:324)~[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
在org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:213)[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
位于org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectCall(SpringJUnit4ClassRunner.java:290)[spring-test-4.0.4.RELEASE.jar:4.0.4.RELEASE]
位于org.junit.internal.runners.model.ReflectVeCallable.run(reflectVeCallable.java:12)[junit-4.11.jar:na]
位于org.springframework.test.context.junit4