启动tomcat时报以下错误:
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'commonDao' defined in ServletContext resource [/WEB-INF/spring-config/bean.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError
Caused by: java.lang.NoClassDefFoundError加入tx.xml就会报错,如果没有的话就可以运行.
bean.xml代码:<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

<bean id="commonDao" class="com.dz.dao.CommonDao" autowire="byType" />

<bean id="permissionAction" class="com.dz.action.PermissionAction" scope="prototype">
<property name="commonDao" ref="commonDao" /><!-- name="commonDao"中的commonDao是PermissionAction的属性 -->
</bean>

</beans>tx.xml代码:<?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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">

<bean id="transactionManager" autowire="byType"
class="org.springframework.orm.hibernate3.HibernateTransactionManager" />
<tx:advice id="transactionAdvice" transaction-manager="transactionManager">

<tx:attributes>
<tx:method name="save*" />
<tx:method name="delete*"/>
<tx:method name="update*"/>
<tx:method name="*" read-only="true"/>
</tx:attributes>
</tx:advice>
<aop:config proxy-target-class="true">
<aop:advisor pointcut="execution(* com.dz.dao.*.*(..))" 
advice-ref="transactionAdvice"  />
</aop:config>


</beans>

解决方案 »

  1.   

    Error creating bean with name 'commonDao' defined in ServletContext resource 无法创建 commonDao bean 无法进行初始化
      

  2.   

    NoClassDefFoundError 缺少了什么类,请查看具体的异常信息
      

  3.   

    com.dz.dao.CommonDao--检查你的源代码里面这个类对应的class文件有吗?
      

  4.   

    如果按楼主描述 加入tx.xml才会报错
    而bean.xml是正常的,那么commonDao bean 应该是可以初始化的之前我配置的时候也是一加入AOP的配置就提示某类无法初始化,而去掉了AOP的配置就正常了
    后面才发现少加了一个类包
    楼主检查一下配置AOP所需要的类包都加了吗
      

  5.   

    class="com.dz.dao.CommonDao"
    应该注入的是对应的dao借口的实现吧,是不是class="com.dz.dao.CommonDaoImpl"