Bean named 'txAdvice' must be of type [org.aopalliance.aop.Advice]

J2EE 码拜 10年前 (2015-04-20) 1865次浏览 0个评论
 

org.springframework.beans.factory.BeanCreationException: Error creating bean with name “”userService”” defined in URL [file:/D:/WorkSpace/apache-tomcat-6.0.33/webapps/SingleUsers/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named “”txAdvice”” must be of type [org.aopalliance.aop.Advice], but was actually of type [org.springframework.transaction.interceptor.TransactionInterceptor]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:913)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:377)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:278)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:111)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
at org.apache.catalina.core.StandardService.start(StandardService.java:525)
at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named “”txAdvice”” must be of type [org.aopalliance.aop.Advice], but was actually of type [org.springframework.transaction.interceptor.TransactionInterceptor]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:353)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.aop.support.AbstractBeanFactoryPointcutAdvisor.getAdvice(AbstractBeanFactoryPointcutAdvisor.java:85)
at org.springframework.aop.aspectj.AspectJProxyUtils.isAspectJAdvice(AspectJProxyUtils.java:67)
at org.springframework.aop.aspectj.AspectJProxyUtils.makeAdvisorChainAspectJCapableIfNecessary(AspectJProxyUtils.java:49)
at org.springframework.aop.aspectj.autoproxy.AspectJAwareAdvisorAutoProxyCreator.extendAdvisors(AspectJAwareAdvisorAutoProxyCreator.java:101)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.findEligibleAdvisors(AbstractAdvisorAutoProxyCreator.java:88)
at org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator.getAdvicesAndAdvisorsForBean(AbstractAdvisorAutoProxyCreator.java:68)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:359)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:322)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:407)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1426)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
… 35 more

Bean named 'txAdvice' must be of type [org.aopalliance.aop.Advice]
配置文件:
<?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-3.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
           http://www.springframework.org/schema/aop
           http://www.springframework.org/schema/aop/spring-aop-3.0.xsd”>
           

<!–  配置SessionFactory –>
<bean id=”sessionFactory”
class=”org.springframework.orm.hibernate3.LocalSessionFactoryBean”>
<!– 使用本地的hibernate.cfg.xml配置文件,这样清晰一点 –>
<property name=”configLocation”>
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>

<bean id=”userDao” class=”com.singleusers.dao.impl.UserDaoImpl”>
<property name=”sessionFactory” ref=”sessionFactory”>
</property>
</bean> 
<bean id=”userService” class=”com.singleusers.service.impl.UserServiceImpl”>
<property name=”userDao” ref=”userDao”></property>
</bean>

<bean id=”addUserAction” class=”com.singleusers.adduser.action.AddUserAction”>
<property name=”service” ref=”userService”></property>
</bean> <!– –>

<!– 配置事物管理器 –>
<bean id=”transactionManager”
class=”org.springframework.orm.hibernate3.HibernateTransactionManager”>
<property name=”sessionFactory” ref=”sessionFactory” />
</bean>

<!– AOP,那些包下面的类需要使用事物管理器 –>
<aop:config>
<aop:pointcut id=”servieMethod”
expression=”execution(* com.singleusers.service.*.*(..))” />
<!– 如果满足servieMethod这个切入点就去 参考事物传播性配置的txAdvice建议–>
<aop:advisor advice-ref=”txAdvice” pointcut-ref=”servieMethod” />
</aop:config>

<!– 事物传播性配置 –>
<tx:advice id=”txAdvice” transaction-manager=”transactionManager”>
<tx:attributes>
<!–
propagation=”REQUIRED” 当前有事物则加入,否则新建一个事物,read-only=”true” 事物是否只读
–>
<tx:method name=”get*” read-only=”true” />
<tx:method name=”find*” read-only=”true” />
<tx:method name=”add*” propagation=”REQUIRED” />
<tx:method name=”update*” propagation=”REQUIRED” />
<tx:method name=”del*” propagation=”REQUIRED” />
</tx:attributes>
</tx:advice>
</beans>

userService哪错了???急求解

Bean named 'txAdvice' must be of type [org.aopalliance.aop.Advice]
有没有人遇到过这样的问题啊,求解,谢谢!
Bean named 'txAdvice' must be of type [org.aopalliance.aop.Advice]
http://blog.csdn.net/nba_2011/article/details/6708812

解决了   jar包冲突
TransactionInterceptor是 org.aopalliance.aop.Advice 的一个实现,可能是Jar包的冲突。
 

到jar包中去查看。
 
 我的问题是: aopalliance-1.0.jar 和 aopalliance-alpha1.jar之间的冲突。
 
 将后者去掉,再运行就OK了。

Bean named 'txAdvice' must be of type [org.aopalliance.aop.Advice]
40分
Bean named “”txAdvice”” must be of type [org.aopalliance.aop.Advice], 
这个异常表明引用的类型不对。。。估计是引用了aopalliance-alpha1.jar包中的Advice了。。

谢谢分享…LZ

Bean named 'txAdvice' must be of type [org.aopalliance.aop.Advice]
引用 4 楼 kouyisc 的回复:

Bean named “”txAdvice”” must be of type [org.aopalliance.aop.Advice], 
这个异常表明引用的类型不对。。。估计是引用了aopalliance-alpha1.jar包中的Advice了。。

谢谢分享…LZ

给分

Bean named 'txAdvice' must be of type [org.aopalliance.aop.Advice]
谢谢LZ解决的我的问题,找了半天。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Bean named 'txAdvice' must be of type [org.aopalliance.aop.Advice]
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!