嵌套异常是java.lang.NoClassDefFoundError:org / springframework / aop / config / AopNamespaceUtils

时间:2015-05-30 10:38:43

标签: java spring

我有一个switchyard应用程序,我在那里定义了一个用于加载应用程序上下文的bean类。

但是,每当我尝试加载应用程序上下文时,我都会收到以下错误:

**30 May 2015 15:52:15,510 ERROR [com.ip.fsw.tt.db.DBHandlerBean] (MSC service thread 1-8) DBHandlerBean|0|Error occured while bean initialization : Unexpected exception parsing XML document from class path resource [applicationContext.xml]; nested exception is java.lang.NoClassDefFoundError: org/springframework/aop/config/AopNamespaceUtils**

这是我的applicationContext.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans default-init-method="beanInit" default-destroy-method="beanDestroy"
    xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    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:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd 
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

    <bean id="decryptPropertyConfigurer" class="com.alu.ipprd.oss.common.util.DecryptPropertyConfigurer">
        <property name="locations">
            <list>
                <value>classpath:tt-db.properties</value>
            </list>
        </property>
    </bean>
    <tx:annotation-driven />
    <bean id="transactionManager" 
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
        <property name="driverClass" value="com.mysql.jdbc.Driver" />
        <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/database" />
        <property name="user" value="tt" />
        <property name="password" value="tt" />
        <property name="acquireIncrement" value="3" />
        <property name="minPoolSize" value="10" />
        <property name="maxPoolSize" value="100" />
        <property name="maxIdleTime" value="3000" />
        <property name="autoCommitOnClose" value="true" />
    </bean>

    <bean id="namingStrategy" class="org.hibernate.cfg.EJB3NamingStrategy"></bean>

    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
        <property name="namingStrategy">
            <ref bean="namingStrategy" />
        </property>
        <property name="annotatedClasses">
            <list>
                <value>com.ip.fsw.tt.db.models.TTroubleticket</value>
                <value>com.ip.fsw.tt.db.models.TTroubleticketalarm
                </value>
            </list>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${MY_SQL_DIALECT}</prop>
                <prop key="hibernate.show_sql">${SHOW_SQL}</prop>
                <prop key="org.hibernate.FlushMode">${FLUSH_MODE}</prop>
                <prop key="hibernate.hbm2ddl.auto">${HBM_2_DDL_AUTO}</prop>
            </props>
        </property>

        <property name="dataSource">
            <ref bean="dataSource" />
        </property>
    </bean>

    <bean id="genericDao" class="com.ip.fsw.tt.db.dao.GenericDao"
        abstract="true">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="tTroubleticketDao" class="com.ip.fsw.tt.db.dao.TTroubleticketDao"
        parent="genericDao" />

    <bean id="tTroubleticketalarmDao" class="com.ip.fsw.tt.db.dao.TTroubleticketalarmDao"
        parent="genericDao" />

    <bean id="ttfacade" class="com.ip.fsw.tt.db.facade.DaoTicketFacade">
        <property name="tTroubleticketDao" ref="tTroubleticketDao" />
        <property name="tTroubleticketalarmDao" ref="tTroubleticketalarmDao" />
    </bean>
</beans>

这是我的DBHandler类,我正在尝试加载应用程序上下文:

package com.ip.fsw.tt.db;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.switchyard.component.bean.Service;

import com.ip.common.logging.jb.Logger;
import com.ip.fsw.tt.db.facade.DaoTicketFacade;

@Service(DBHandler.class)
public class DBHandlerBean implements DBHandler {
    private Logger logger = Logger.getLogger(DBHandlerBean.class);
    public static DaoTicketFacade ttfacade;
    public DBHandlerBean() {
        logger.info("DBHandlerBean",0,"Loading AppContext","");
        if(loadAppContext()){
            logger.info("DBHandlerBean",0,"AppContext Successfully loaded","");
        }
    }

    private boolean loadAppContext() {
        try {
            ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
            ttfacade = (DaoTicketFacade)context.getBean("ttfacade");
        } catch(BeansException e) {
            logger.error("DBHandlerBean",0,"Error occured while bean initialization : "+e.getMessage(),"");
        } catch (Exception e) {
            logger.error("DBHandlerBean",0,"Error occured while loading the application context : "+e.getMessage(),"");
        } 
        if(ttfacade!=null){
            logger.info("DBHandlerBean",0,"Spring context loaded","");  
            return true;
        } else {
            logger.error("DBHandlerBean",0,"Spring context could not be loaded ","");
        }
        return false;
    }

    @Override
    public DaoTicketFacade getFacade() {
        // TODO Auto-generated method stub
        return null;
    }
}

现在请告诉我如何解决这个问题。

修改

这是pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <modelVersion>4.0.0</modelVersion>
    <groupId>com.ip.tt</groupId>
    <artifactId>platform-tt</artifactId>
    <version>3.2.0-SNAPSHOT</version>
    <name>platform-tt</name>

    <properties>
        <switchyard.version>1.1.0.Final</switchyard.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>4.0.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>4.0.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.2.0.SP1</version>
        </dependency>
        <!-- <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-c3p0</artifactId>
            <version>4.2.7.SP1</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-infinispan</artifactId>
            <version>4.2.0.SP1</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.2.0.SP1</version>
        </dependency> -->

        <dependency>
            <groupId>c3p0</groupId>
            <artifactId>c3p0</artifactId>
            <version>0.9.1.2</version>
        </dependency>
        <dependency> 
            <groupId>net.sourceforge.saxon</groupId> 
            <artifactId>saxonhe</artifactId> 
            <version>9.2.1.5</version> 
        </dependency>

        <dependency>
            <groupId>org.jboss.as</groupId>
            <artifactId>jboss-as-security</artifactId>
            <version>7.1.1.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jasypt</groupId>
            <artifactId>jasypt</artifactId>
            <version>1.9.0</version>
        </dependency>

        <dependency>
            <groupId>jboss</groupId>
            <artifactId>jboss-remoting</artifactId>
            <version>4.2.2.GA</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>4.0.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.alu.ipprd.aor.common.log</groupId>
            <artifactId>aor-plf-common-logging</artifactId>
            <version>0.0.1-SNAPSHOT</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>3.0.7.RELEASE</version>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>3.0.7.RELEASE</version>
        </dependency>
        <!-- Switchyard Dependencies -->
        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>switchyard-component-bean</artifactId>
            <version>${switchyard.version}</version>
        </dependency>
        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>switchyard-component-camel</artifactId>
            <version>${switchyard.version}</version>
        </dependency>
        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>switchyard-component-rules</artifactId>
            <version>${switchyard.version}</version>
        </dependency>
        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>switchyard-component-camel-quartz</artifactId>
            <version>${switchyard.version}</version>
        </dependency>
        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>switchyard-component-soap</artifactId>
            <version>${switchyard.version}</version>
        </dependency>
        <dependency>
            <groupId>org.switchyard</groupId>
            <artifactId>switchyard-api</artifactId>
            <version>${switchyard.version}</version>
        </dependency>
        <dependency>
            <groupId>org.switchyard</groupId>
            <artifactId>switchyard-transform</artifactId>
            <version>${switchyard.version}</version>
        </dependency>
        <dependency>
            <groupId>org.switchyard</groupId>
            <artifactId>switchyard-validate</artifactId>
            <version>${switchyard.version}</version>
        </dependency>
        <dependency>
            <groupId>org.switchyard</groupId>
            <artifactId>switchyard-plugin</artifactId>
            <version>${switchyard.version}</version>
        </dependency>
        <dependency>
            <groupId>org.switchyard</groupId>
            <artifactId>switchyard-test</artifactId>
            <version>${switchyard.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>switchyard-component-test-mixin-cdi</artifactId>
            <version>${switchyard.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>commons-codec</groupId>
            <artifactId>commons-codec</artifactId>
            <version>1.6</version>
        </dependency>

        <!-- Module Dependencies -->
        <!-- <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.2.0.SP1</version>
            <scope>system</scope> <systemPath>${basedir}/lib/hibernate-core-4.2.0.SP1-redhat-1.jar</systemPath>
        </dependency> -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.21</version>
            <!-- <scope>system</scope> <systemPath>${basedir}/lib/mysql-connector-java-5.1.21.jar</systemPath> -->
        </dependency>
        <!-- <dependency> <groupId>net.sf.ehcache</groupId> <artifactId>ehcache</artifactId> 
            <version>2.7.2</version> </dependency> -->

        <dependency>
            <groupId>org.switchyard.components</groupId>
            <artifactId>
                switchyard-component-test-mixin-http
            </artifactId>
            <version>${switchyard.version}</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                    <debug>true</debug>
                    <showWarnings>true</showWarnings>
                    <showDeprecation>true</showDeprecation>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.switchyard</groupId>
                <artifactId>switchyard-plugin</artifactId>
                <version>${switchyard.version}</version>
                <!-- <executions>
                    <execution>
                        <goals>
                            <goal>configure</goal>
                        </goals>
                    </execution>
                </executions> -->
                <configuration>
                    <scannerClassNames>
                        <param>
                            org.switchyard.transform.config.model.TransformSwitchYardScanner
                        </param>
                    </scannerClassNames>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

2 个答案:

答案 0 :(得分:0)

当您在编译期间拥有该类但在运行时它不存在时,通常会抛出

NoClassDefFoundError

请针对任何jar冲突彻底检查您的maven依赖项。这可能是NoClassDefFoundError的可能原因。

同时检查你的pom.xml并导航到依赖关系层次结构选项卡,以验证你是否两次看不到同一个不同版本的jar。

如果您确实有jar冲突,则必须根据您使用特定版本的要求删除其中一个冲突。

在我的情况下,spring-aop jar在编译时出现,但是当我将项目部署到JBoss EAP服务器时,它无法找到spring-aop jar。所以我在JBoss EAP模块目录中添加了spring-aop jar,之后我的项目选择了jar文件。

答案 1 :(得分:-1)

您正在混合命名空间版本(3.1,3.0,2.0)。

请遵循使用3.2

的示例

&#13;
&#13;
s
&#13;
&#13;
&#13;