Spring 声明式事务在SSH框架中的配置问题

Emerson_Li 2009-06-01 02:27:33
我在做SSH项目的时候使用Spring的声明式事务代理,开发环境用的是myeclipse。在tomcat启动后报了如下错误
(错误内容太长,详细见附件)
ERROR - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor': Instantiation of bean failed; nested exception is java.lang.AbstractMethodError: org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.determineConstructor(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/reflect/Constructor;
Caused by: java.lang.AbstractMethodError: org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.determineConstructor(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/reflect/Constructor;
at
.........................................
2009-6-1 0:19:36 org.apache.catalina.core.StandardContext listenerStart
严重: 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 'org.springframework.aop.support.DefaultBeanFactoryPointcutAdvisor': Instantiation of bean failed; nested exception is java.lang.AbstractMethodError: org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.determineConstructor(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/reflect/Constructor;
Caused by: java.lang.AbstractMethodError: org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.determineConstructor(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/reflect/Constructor;
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:743)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:716)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:387)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:251)
at

我在网上查了很久,发现出现这类错误的例子很少,没看到什么有效的解决办法。由于不是很懂Spring内部机制。所以源码也没看懂什么名堂。

我Spring 配置文件是这样的:

<?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.5.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="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="configLocation"
value="classpath:hibernate.cfg.xml">
</property>
</bean>


<!-- 配置事务管理器 -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory">
<ref local="sessionFactory"/>
</property>
</bean>

<!-- 配置事务的传播特性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager" >
<tx:attributes>
<!-- 在开发的时候可以这样定义,但部署的时候一定要详细定义 -->
<tx:method name="*" propagation="REQUIRED"/>
<!--
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="del*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="*" read-only="true"/>
-->
</tx:attributes>
</tx:advice>

<!-- 配置哪些类哪些方法使用事务 -->
<aop:config>
<aop:pointcut id="txAdvicePointcut" expression="execution(* com.nuist.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txAdvicePointcut"/>
</aop:config>
</beans>



用的是尚学堂事务声明的模板,web配置文件如下:


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>


出问题的应该是这段配置:

<aop:config>
<aop:pointcut id="txAdvicePointcut" expression="execution(* com.nuist.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txAdvicePointcut"/>
</aop:config>
...全文
660 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
shmily 2011-07-01
  • 打赏
  • 举报
回复
楼主是个JB
jinyfeng 2011-05-25
  • 打赏
  • 举报
回复
大哥,是哪些jar包冲突啊,你说出来啊,不然别人遇到同样的问题怎么办啊?
记忆回到从前 2010-12-07
  • 打赏
  • 举报
回复
大哥,哪些jar出了问题,你说下啊,都遇到问题了
a17587060 2009-09-28
  • 打赏
  • 举报
回复
是哪几个 jar 包有冲突,写出来呀......
Emerson_Li 2009-06-04
  • 打赏
  • 举报
回复
已解决,是struts的jar包和spring的jar包冲突。看在3楼回复那么多的份上给分吧~~~
Emerson_Li 2009-06-01
  • 打赏
  • 举报
回复
楼上的,我试过了,加public还是不行~~
tjyyyatjp 2009-06-01
  • 打赏
  • 举报
回复
以下是我成功的一个配置例子

<?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" xmlns:p="http://www.springframework.org/schema/p" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.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-2.0.xsd">
- <!-- session工厂
-->
- <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="configLocation" value="classpath:hibernate.cfg.xml" />
</bean>
- <!-- session模板
-->
- <bean id="ht" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
- <!-- Dao 数据库访问通用类
-->
- <bean id="basicDao" class="tjy.hrm.common.BasicHibernateDaoImpl">
<property name="hibernateTemplate" ref="ht" />
</bean>
- <bean id="parentDao" abstract="true">
<property name="common" ref="basicDao" />
</bean>
<bean id="userDao" class="tjy.hrm.dao.UserDaoImpl" parent="parentDao" />
<bean id="funcDao" class="tjy.hrm.dao.FuncDaoImpl" parent="parentDao" />
<bean id="posDao" class="tjy.hrm.dao.PosDaoImpl" parent="parentDao" />
<bean id="funcTypeDao" class="tjy.hrm.dao.FuncTypeDaoImpl" parent="parentDao" />
<bean id="deptDao" class="tjy.hrm.dao.DeptDaoImpl" parent="parentDao" />
- <!-- Biz 权限模块业务类
-->
- <bean id="popedomBiz" class="tjy.hrm.biz.PopedomBizImpl">
<property name="deptDao" ref="deptDao" />
<property name="userDao" ref="userDao" />
<property name="posDao" ref="posDao" />
<property name="funcTypeDao" ref="funcTypeDao" />
<property name="funcDao" ref="funcDao" />
</bean>
- <!-- Action
-->
- <bean name="/popedom" class="tjy.hrm.actions.PopedomAction">
<property name="popedomBiz" ref="popedomBiz" />
</bean>
- <!-- 事务管理器
-->
- <bean id="htm" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
- <!-- 将事务代码以通知的形式织入业务类
-->
- <tx:advice id="ad" transaction-manager="htm">
- <tx:attributes>
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
- <aop:config>
<aop:pointcut id="pc" expression="execution(public * tjy.hrm.biz.*.*(..))" />
<aop:advisor advice-ref="ad" pointcut-ref="pc" />
</aop:config>
</beans>
tjyyyatjp 2009-06-01
  • 打赏
  • 举报
回复
在表达式里加个 public 访问修饰符
tjyyyatjp 2009-06-01
  • 打赏
  • 举报
回复

<aop:config>
<aop:pointcut id="txAdvicePointcut" expression="execution(public* com.nuist.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txAdvicePointcut"/>
</aop:config>

这里这样设置一下
临远 2009-06-01
  • 打赏
  • 举报
回复
很可能因为jar版本有问题。

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧