【问题标题】:What s wrong with applicationContext.xml fileapplicationContext.xml 文件有什么问题
【发布时间】:2014-03-09 16:28:38
【问题描述】:

我正在尝试将 dtatbase 连接到我的 Web 应用程序。 MSSQL 服务器中的数据库。这是我的 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"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd">

    <bean id="txManagerDH" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
          <property name="sessionFactory" ref="dhSessionFactory"/>
    </bean>

    <tx:annotation-driven transaction-manager="txManagerDH"/>      

<bean id="dhDataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource"
    p:driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
    p:url="jdbc:sqlserver://TARAS-PC\SQLEXPRESS:1433:databaseName=DH:"
    p:username="GlassfishDH"
    p:password="glassfish" />

    <bean id="dhSessionFactory"
          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
          p:dataSource-ref="dhDataSource">
        <property name="annotatedClasses">
            <list>
                <value>model.User</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">
                    org.hibernate.dialect.SQLServerDialect
                </prop>
                <prop key="hibernate.show_sql">false</prop>
            </props>
        </property>
    </bean>

    <bean id="UserDao" class="model.UserDao" p:sessionFactory-ref="dhSessionFactory"/>

    <bean id="UserService" class="service.UserService"
        p:userDao-ref="UserDao"/>

</beans>

当我尝试运行它时出现错误:

部署期间发生错误:加载应用程序时出现异常: java.lang.IllegalStateException:ContainerBase.addChild:开始: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException:错误 创建在 ServletContext 中定义的名称为 'txManagerDH' 的 bean 资源[/WEB-INF/applicationContext.xml]:之前的BeanPostProcessor bean 的实例化失败;嵌套异常是 java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice.请参见 server.log 了解更多详情。

我不知道我的代码有什么问题。请帮帮我。

【问题讨论】:

  • java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice. Please see server.log for more details. ==> 看看服务器日志

标签: java xml web-applications


【解决方案1】:

您的类路径中缺少 aop-alliance 库。你可以获取二进制或maven依赖here

或者,获取完整的 spring-aop 库。

【讨论】:

  • 我下载了 aopalliance.jar 文件并将其添加到我的项目中,所以我有同样的错误
  • @user3079114 我怀疑你有 same 错误。请再次检查。
  • 是的,我有同样的错误。我尝试重新启动我的项目,但同样的问题。
  • @user3079114 然后我会要求你把你在WEB-INF/libs文件夹中的所有罐子都给我们。
  • sqljdbc.jar 和 aopalliance.jar
【解决方案2】:

如果您面临同样的问题,那么您错过了 aopalliance.jar。在此位置,您可以加载 jar http://mvnrepository.com/artifact/aopalliance/aopalliance/1.0。此外,建议您使用 Maven 来处理所有这些依赖项,而不是自己做。我在这里遇到了同样的问题,它已经解决了。这是我的帖子:Not able to load the applicationContext.xml in Spring。如果这个问题得到解决,那么 spring 4.0.0 与 hibernate 4.30 的兼容性将会有另一个问题。

在 dipatcher-servlet 中,而不是

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

使用

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-08
    • 2021-05-03
    • 2013-02-17
    • 2012-05-26
    • 2014-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多