日期:2014-05-20  浏览次数:20800 次

spring框架下注解事务出现的异常
我在用注解事务的时候出现下面的异常
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [beans.xml]: BeanPostProcessor before instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: org/aopalliance/aop/Advice
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:452)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at questionTest.QuestionTest.main(QuestionTest.java:18)

关建代码如下:
beans里面的<?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:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"> 
  
  <!-- 配置数据源 -->
  <bean id="dataSource"
  class="org.springframework.jdbc.datasource.DriverManagerDataSource">
  <!-- 驱动类 -->
  <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
  <!-- driverUrl连接串 -->
  <property name="url" value="jdbc:sqlserver://localhost:1433; DatabaseName=yd_Test"/>
  <!-- 用户名 -->
  <property name="username" value="sa"/>
  <!-- 密码 -->
  <property name="password" value="123456"/>
</bean>
  <bean name="QuestionDAO" class="com.zy.DAO.QuestionDAO">
  <property name="dataSource" ref="dataSource"/>
  <property name="transactionManager" ref="transactionManager"/>
  </bean>
  <!-- 注解事务 -->
 <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">  
  <property name="dataSource" ref="dataSource"></property>  
</bean>  
  <tx:annotation-driven transaction-manager="transactionManager" />
<bean name="QuestionItemDAO" class="com.zy.DAO.QuestionItemDAO">
  <property name="dataSource" ref="dataSource"/>
</bean>
<bean name="QuestionTypeDAO" class="com.zy.DAO.QuestionTypeDAO">