首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

spring AOP中Cglib 代理配置有关问题,各位指点一上

2013-09-11 
springAOP中Cglib 代理配置问题,各位指点一下。本帖最后由 gabiymy 于 2013-02-21 17:27:10 编辑bean id

spring AOP中Cglib 代理配置问题,各位指点一下。
本帖最后由 gabiymy 于 2013-02-21 17:27:10 编辑 <bean id="aopHelper" class="com.common.AopHelper" ></bean>
    <aop:config proxy-target-class="true" >
    <!-- 定义一个切面 -->
    <aop:aspect  ref="aopHelper">
     <!-- 定义切入点 -->  
     <aop:pointcut id="myAspect" expression="execution(* *.insert*(..))" />
     <!-- 前置通知 -->  
         <aop:before pointcut-ref="myAspect" method="before"/>
    </aop:aspect>
</aop:config>
意思就是所有的insert开头的方法切到class="com.common.AopHelper"这个类里面。这个类里面就写了一个方法
public void before(){
        System.out.println("我已经开始要记录操作行为了。");
    }

系统报错
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClientTemplate' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'sqlMapClient' while setting bean property 'sqlMapClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient': Post-processing of the FactoryBean's object failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ibatis.sqlmap.engine.impl.SqlMapClientImpl]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:107)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1391)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient': Post-processing of the FactoryBean's object failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ibatis.sqlmap.engine.impl.SqlMapClientImpl]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:165)

Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ibatis.sqlmap.engine.impl.SqlMapClientImpl]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given


at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:217)

Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at org.springframework.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:721)
at org.springframework.cglib.proxy.Enhancer.generateClass(Enhancer.java:499)

2013-2-21 17:16:13 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 'sqlMapClientTemplate' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Cannot resolve reference to bean 'sqlMapClient' while setting bean property 'sqlMapClient'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient': Post-processing of the FactoryBean's object failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ibatis.sqlmap.engine.impl.SqlMapClientImpl]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlMapClient': Post-processing of the FactoryBean's object failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ibatis.sqlmap.engine.impl.SqlMapClientImpl]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:165)

... 30 more
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class [class com.ibatis.sqlmap.engine.impl.SqlMapClientImpl]: Common causes of this problem include using a final class or a non-visible class; nested exception is java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given
at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:217)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110)

... 35 more
Caused by: java.lang.IllegalArgumentException: Superclass has no null constructors but no arguments were given


at org.springframework.cglib.proxy.Enhancer.emitConstructors(Enhancer.java:721)

... 42 more spring java
[解决办法]
呵呵,前几天我也遇到了这个问题。下面是解决办法:
aop代理分为jdk接口代理和cglib类代理,通过proxy-target-class来控制。
你写了 proxy-target-class="true" ,说明你要代理的是类而不是接口。
而expression="execution(* *.insert*(..))",是所有有insert*方法的类都要代理,你查一下这些类是不是有的实现了接口,所以就报错了。
你可以把expression详细点不要写的这么宽泛,比如
expression="execution(* com.ssh.user.action.UserAction.*(..))",UserAction类不要实现接口。

这就搞定了,结贴给分吧~

热点排行