我正在尝试使用spring + jsf + hibernate在tomcat中运行应用程序,但我发现以下错误:
SEVERE:将上下文初始化事件发送给侦听器的异常 类的实例 org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanDefinitionStoreException: 从ServletContext资源解析XML文档时出现意外异常 [/WEB-INF/spring-config.xml];嵌套异常是 java.lang.NoClassDefFoundError: org / aopalliance / intercept / MethodInterceptor at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412) 在 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
我的spring-config.xml:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
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.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd">
<bean id="cadastraPacienteMB"
class="br.com.prontuario.mb.CadastraPaciente"
scope="session"/>
<bean id="pesquisaPacienteMB"
class="br.com.prontuario.mb.PesquisaPaciente"
scope="session">
<property name="editaPaciente" ref="editaPacienteMB"/>
</bean>
<bean id="editaPacienteMB"
class="br.com.prontuario.mb.EditaPaciente"
scope="session"/>
<tx:annotation-driven transaction-manager="txManager"/>
<context:annotation-config />
<!-- Gerenciador de transacoes baseado em JPA -->
<bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
<property name="dataSource" ref="myDataSource" />
</bean>
<!-- Fabrica de entity managers -->
<bean id="entityManagerFactory"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
<property name="database" value="PostgreSQL" />
</bean>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop>
</props>
</property>
</bean>
<!-- DataSource configurado para o banco de dados da aplicacao -->
<bean id="myDataSource"
class="org.apache.tomcat.dbcp.dbcp.BasicDataSource">
<property name="driverClassName" value="org.postgresql.Driver" />
<property name="url" value="jdbc:postgresql://localhost:5433/postgres" />
<property name="username" value="postgres" />
<property name="password" value="postgres" />
</bean>
</beans>
答案 0 :(得分:2)
您正在使用spring-tx(因为您正在使用tx:annotation-driven)。 spring-tx依赖于aopaliance,你的类路径中缺少这个jar:
java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor
您可以在以下网址找到它:
http://mirrors.ibiblio.org/pub/mirrors/maven/aopalliance/jars/aopalliance-1.0.jar
或(更好)使用maven ......