`
zhaoshun0417
  • 浏览: 6607 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
文章分类
社区版块
存档分类
最新评论

spring的cglib问题

阅读更多
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

<bean id="myPointcutAdvisor"
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
<property name="advice">
<ref local="MyInterceptor" />
</property>
<property name="patterns">
<list>
<value>.*do.*</value>
<value>.*action.*</value>
</list>
</property>

</bean>

<bean id="MyInterceptor" class="com.MethodTimeCostInterceptor">
</bean>
<bean id="myProxyAop"
class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="proxyTargetClass">
<value>true</value>
</property>
<property name="target">
<ref local="service" />
</property>

<property name="interceptorNames">
<value>myPointcutAdvisor</value>
</property>

</bean>
   <bean id="service" class="com.ServiceImpl" lazy-init="true" />
</beans>
测试代码
package com;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

public class Demo {

public static void main(String[] args) {
ApplicationContext cxt =
new FileSystemXmlApplicationContext("classpath:applicationContext.xml");
ServiceImpl service = (ServiceImpl)cxt.getBean("service");
System.out.println(service);
service.doTest();
}
}

这个配置相信大家都会,但是在Myeclipse6.0下导入spring的jar包。会报这个错误
net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
发现竟然是jar包不兼容导致。是Myeclipse6.0自动导入的spring的jar包问题。是自动导入的cglib包有问题。
自己实现cglib也出现过同样的问题。后面自己导入cglib包,发现少asm包,需要导入 hibernate包就可以正常运行。
解决方案:
  把自动导入的jar包删除。重新导入jar包即可。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics