spring AOP中Cglib 代理配置问题,各位指点一下。

星球本色 2013-02-21 05:26:05
<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
...全文
937 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
diaoyubing 2013-02-28
  • 打赏
  • 举报
回复
呵呵,不是的,看来还没明白我的意思。 AopHelper类与cglib代理无关。 项目中用的最多的就是cglib代理,最好是弄明白他。可以到网上搜搜“spring事务管理”方面的例子,试验下。
星球本色 2013-02-28
  • 打赏
  • 举报
回复
引用 1 楼 diaoyubing 的回复:
呵呵,前几天我也遇到了这个问题。下面是解决办法: aop代理分为jdk接口代理和cglib类代理,通过proxy-target-class来控制。 你写了 proxy-target-class="true" ,说明你要代理的是类而不是接口。 而expression="execution(* *.insert*(..))",是所有有insert*方法的类都要代理,你查……
兄弟,我换了一种方式做出来的。这种方式没调出来啊。我那个AopHelper类是不是需要写一些cglib方面的代码啊。
diaoyubing 2013-02-22
  • 打赏
  • 举报
回复
呵呵,前几天我也遇到了这个问题。下面是解决办法: aop代理分为jdk接口代理和cglib类代理,通过proxy-target-class来控制。 你写了 proxy-target-class="true" ,说明你要代理的是类而不是接口。 而expression="execution(* *.insert*(..))",是所有有insert*方法的类都要代理,你查一下这些类是不是有的实现了接口,所以就报错了。 你可以把expression详细点不要写的这么宽泛,比如 expression="execution(* com.ssh.user.action.UserAction.*(..))",UserAction类不要实现接口。 这就搞定了,结贴给分吧~

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧