我有一个开关场应用程序,在那里我定义了一个用于加载应用程序上下文的 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>
最佳答案
您正在混合命名空间版本(3.1、3.0、2.0)。
按照这个使用 3.2 的例子
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<beans xmlns="http://www.springframework.org/schema/beans"
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:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
关于java - 嵌套异常是 java.lang.NoClassDefFoundError : org/springframework/aop/config/AopNamespaceUtils,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30545086/