1

我正在尝试使用 spring + jsf + hibernate 在 tomcat 中运行应用程序,但出现以下错误:

严重:向类 org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanDefinitionStoreException 的侦听器实例发送上下文初始化事件的异常:从 ServletContext 资源 [/WEB-INF/spring-config.xml 解析 XML 文档时出现意外异常]; 嵌套异常是 org.springframework.beans.factory.xml.XmlBeanDefinitionReader 中 org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:412) 中的 java.lang.NoClassDefFoundError: org/aopalliance/intercept/MethodInterceptor。 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>
4

1 回答 1

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 ...

于 2013-06-21T16:39:26.153 回答