整合Spring与Struts2时配置AOP启动Tomcat报错
平台用的是MyEclipse8.5 服务器 Tomcat 5.
在整合的过程中 用Spring 配置bean管理是可以正常运行的 但是配置AOP时 两种方式都会报错
applicationContext.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"
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.5.xsd">
<!--
<aop:aspectj-autoproxy /> <bean id="log" class="com.leng.aspect.Log"/>
-->
<bean id="aop" class="com.leng.aspect.Log" />
<aop:config>
<!-- 配置切面aspect,ref切面类 -->
<aop:aspect id="logaspect" ref="aop">
<!--配置切入点Pointcut,定义一个表达式 -->
<aop:pointcut
expression="execution(*
com.leng.service.impl.UserServiceImpl.*(..))"
id="method" />
<!--设置before advice -->
<aop:before method="before" pointcut-ref="method" />
</aop:aspect>
</aop:config>
<bean name="userServiceImpl" class="com.leng.service.impl.UserServiceImpl" />
<bean name="user" class="com.leng.bean.User" />
<bean name="userAction" class="com.leng.action.UserAction">
<property name="user">
<ref bean="user" />
</property>
<property name="userServiceImpl">
<ref bean="userServiceImpl" />
</property>
</bean>
</beans>
部分报错信息(bean的配置肯定是正确的)
1-12-22 14:39:34 INFO DefaultListableBeanFactory:421 - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@510e39: defining beans [aop,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.aop.aspectj.AspectJPointcutAdvisor#0,method,userServiceImpl,user,userAction]; root of factory hierarchy
11-12-22 14:39:34 ERROR ContextLoader:215 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userAction' defined in ServletContext resource [/WEB-INF/classes/applicationContext.xml]: Initialization of bean failed; nested exception is org.springframework.beans.TypeMismatchException: Failed to convert property value of type [$Proxy0 implementing com.leng.service.UserService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.leng.service.impl.UserServiceImpl] for property 'userServiceImpl'; nested exception is java.lang.IllegalArgumentException: Cannot convert value of type [$Proxy0 implementing com.leng.service.UserService,org.springframework.aop.SpringProxy,org.springframework.aop.framework.Advised] to required type [com.leng.service.impl.UserServiceImpl] for property 'userServiceImpl': no matching editors or conversion strategy found
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:480)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
我自己觉得是不是jar包冲突了 可惜找不到答案 下面列出我使用的JAR包
Struts2-spring-plugin-2.2.3.1.jar
asm-all-3.0.jar
log4j
asm-3.1.jar
asm-commoms-3.1.jar
asm-tree-3.1.jar
commons-lang
freemarker-2.3.16
javassist-3.11.0
struts-core
xwork-core
aspectjrt
aspectjweaver
cglib.nodep-2.1_3.jar
common-annotations
commons-logging
spring.jar
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Cannot convert value of type [$Proxy0 implementing com.leng.service.UserService,
UserServiceImpl implement UserService ???
aop拦截的类必须以接口的方式引用。
即com.leng.action.UserAction 中必须用接口的方式引用那个 UserServiceImpl
即UserServiceImpl必须实现某个接口,而UserAction中定义了接口的变量和set方法。
或者使用Bean
org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator
还需要配置2个属性才行。具体的你百度吧