我正在尝试将 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>
当我尝试运行它时,出现错误:
Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'txManagerDH' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice. Please see server.log for more details.
我不知道我的代码有什么问题。请帮助我。
最佳答案
您的类路径中缺少 aop-alliance
库。您可以获取二进制文件或maven依赖项here .
或者,获取完整的 spring-aop
库。
关于java - applicationContext.xml 文件有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22284769/