整合Spring与Struts2时配置AOP启动Tomcat报错

wjfleng 发布于 2011/12/22 14:46
阅读 1K+
收藏 0

平台用的是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

 

加载中
0
刘柳
刘柳

aop拦截的类必须以接口的方式引用。

即com.leng.action.UserAction 中必须用接口的方式引用那个 UserServiceImpl

即UserServiceImpl必须实现某个接口,而UserAction中定义了接口的变量和set方法。

或者使用Bean

org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator

还需要配置2个属性才行。具体的你百度吧

 

0
newtypelv_9
newtypelv_9

Cannot convert value of type [$Proxy0 implementing com.leng.service.UserService,

UserServiceImpl implement UserService ???

返回顶部
顶部