启动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>
严重: 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>
解决方案 »
- SessionFactory问题
- myeclipse下究竟怎样整合struts spring hibernate呀?
- Java天下群(17129182) - 欢迎各Java爱好者加入
- tomcat数据源,用纯java方式出现 javax.naming.NoInitialContextException
- 行业实时系统架构方案讨论,请高手涌跃发言,多谢!
- 如何使JTable的列不可移动?
- 關于Java的說明文檔!!!
- b/s开发过程--等待中
- 为什么用ant 编译j2eetutorial1.4中的bank例子出错
- 请教小问题jms
- 这个action怎么不能访问
- 在FreeMarker做的网站代码下如何修改页面效果?
而bean.xml是正常的,那么commonDao bean 应该是可以初始化的之前我配置的时候也是一加入AOP的配置就提示某类无法初始化,而去掉了AOP的配置就正常了
后面才发现少加了一个类包
楼主检查一下配置AOP所需要的类包都加了吗
应该注入的是对应的dao借口的实现吧,是不是class="com.dz.dao.CommonDaoImpl"