关于网友提出的“整合Spring与Struts2时配置AOP启动Tomcat报错”问题疑问,本网通过在网上对“整合Spring与Struts2时配置AOP启动Tomcat报错”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:
问题:整合Spring与Struts2时配置AOP启动Tomcat报错
描述:平台用的是MyEclipse8.5 服务器 Tomcat 5.
在整合的过程中 用Spring 配置bean管理是可以正常运行的 但是配置AOP时 两种方式都会报错
applicationContext.xml
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">
expression="execution(*
com.leng.service.impl.UserServiceImpl.*(..))"
id="method" />
部分报错信息(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
解决方案1:Cannot convert value of type [$Proxy0 implementing com.leng.service.UserService,
UserServiceImpl implement UserService ???
解决方案2:aop拦截的类必须以接口的方式引用。
即com.leng.action.UserAction 中必须用接口的方式引用那个 UserServiceImpl
即UserServiceImpl必须实现某个接口,而UserAction中定义了接口的变量和set方法。
或者使用Bean
org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator
还需要配置2个属性才行。具体的你百度吧
以上介绍了“整合Spring与Struts2时配置AOP启动Tomcat报错”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1316268.html