如何解决上下文初始化失败?

时间:2015-04-21 06:39:38

标签: java xml maven spring-mvc javabeans

部署代码时获取异常。我尝试了很多可能但无法解决此问题。这是因为maven依赖性而发生的吗?有人可以帮助我摆脱这个问题。

    org.springframework.web.context.ContextLoader - Context initialization failed
        org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'configurationStatusLogDAOImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.vmware.vrack.vrm.core.configuration.dao.ConfigurationStatusLogDAOImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [vrm-postgre-context.xml]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver
          org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) ~[spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) ~[spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) ~[spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) ~[spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) ~[spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700) ~[spring-beans-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[spring-context-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) ~[spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) ~[spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) [spring-web-4.0.1.RELEASE.jar:4.0.1.RELEASE]
        at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:5016) [catalina.jar:7.0.61]
        at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5528) [catalina.jar:7.0.61]
        at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) [catalina.jar:7.0.61]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575) [catalina.jar:7.0.61]
        at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565) [catalina.jar:7.0.61]
        at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_67]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_67]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_67]

下面的代码是context.xml文件,此错误表示

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

                        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <tx:annotation-driven transaction-manager="transactionManager" />
    <bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
        <property name="packagesToScan">
            <list>
                <value>com.vmware.vrack.vrm.security.auth.entity</value>
                <value>com.vmware.vrack.vrm.security.audit.entity</value>
                <value>com.vmware.vrack.vrm.core.property.entity</value>
                <value>com.vmware.vrack.vrm.core.configuration.entity</value>
                <value>com.vmware.vrack.vrm.core.vcenter.entity</value>
                <value>com.vmware.vrack.vrm.core.physical</value>
                <value>com.vmware.vrack.vrm.prm.**.*</value>
                <value>com.vmware.vrack.vrm.event</value>
                <value>com.vmware.vrack.vrm.core.bundlemgmt</value>
                <value>com.vmware.vrack.vrm.core.psc</value>
                <value>com.vmware.vrack.vrm.lcm.entity</value>
                <value>com.vmware.vrack.vrm.security.password.entity</value>
                <value>com.vmware.vrack.vrm.pmm.entity</value>
                <value>com.vmware.vrack.vrm.security.profile.entity</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${jdbc.hibernate.dialect}</prop>
                <prop key="hibernate.show_sql">false</prop>
                <!--<prop key="current_session_context_class">thread</prop>-->
            </props>
        </property>
    </bean>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
        <property name="driverClassName" value="${jdbc.driver.className}" />
        <property name="url" value="${jdbc.url}" />
        <property name="username" value="${jdbc.username}" />
        <property name="password" value="${jdbc.password}" />
        <property name="initialSize" value="${jdbc.connections.initialsize}" />
        <property name="maxActive" value="70" />
        <property name="testOnBorrow" value="true" />
        <property name="validationQuery" value="SELECT 1"/>
    </bean>

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

</beans>

1 个答案:

答案 0 :(得分:2)

错误的主要原因是:

java.lang.NoClassDefFoundError: org/hibernate/util/DTDEntityResolver

因此,您必须将hibernate-<version>.jar添加到类路径中。