Spring AO问题

walkman154 2008-10-29 12:29:40
老是提示这样的错误
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loggerBean' defined in class path resource [test/applicationContext.xml]:
Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Couldn't generate CGLIB subclass of class [class test.LogBean]:
Common causes of this problem include using a final class or a non-visible class; nested exception is net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null

配置文件

<?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.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<bean id="loggerBean" name="loggerBean" class="test.LogBean"/>
<bean id="aopBean" class="test.AOPBean" />
<aop:config>
<aop:pointcut id="loggerCalls"
expression="execution(public * *(..))" />

<aop:aspect id="logAspect" ref="loggerBean">
<aop:around pointcut-ref="loggerCalls" method="aroundLogCalls"/>
</aop:aspect>
</aop:config>

</beans>

LogBean.java文件
package test;

import org.aspectj.lang.ProceedingJoinPoint;


public class LogBean {
public Object aroundLogCalls(ProceedingJoinPoint joinPoint)throws Throwable{

System.out.println("before invoke method:"+joinPoint.getSignature().getName());

Object obj = joinPoint.proceed();

System.out.println("After invoke methond:"+joinPoint.getSignature().getName());

return obj;
}

}


AOPBean文件
package test;

public class AOPBean {
public void display(){
System.out.println("AOPBean.display()");
}

}


AOPMain文件
package test;

import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AOPMain {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
ClassPathXmlApplicationContext factory =
new ClassPathXmlApplicationContext("test/applicationContext.xml");

AOPBean aopbean = (AOPBean)factory.getBeanFactory().getBean("aopBean");
aopbean.display();
}

}




...全文
139 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
jumpheightway 2008-11-17
  • 打赏
  • 举报
回复
这是有关aop里面出的问题
他那个包有问题
cssteven 2008-11-05
  • 打赏
  • 举报
回复
Couldn't generate CGLIB 说明少包了
sunhualong5560 2008-10-29
  • 打赏
  • 举报
回复

ClassPathXmlApplicationContext factory = 
new ClassPathXmlApplicationContext("test/applicationContext.xml");


test/applicationContext.xml这个路径是对的吗?

你有src目录吗?如果有就改成src/applicationContext.xml要是还是不行.
就把全路径写上去试一试

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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