Spring 配置AOP切面注解报错,求教大虾~

anjx007 2013-05-17 09:00:55
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:component-scan base-package="aop.annotation" />
<aop:aspectj-autoproxy/ >
</beans>
在配置<aop:aspectj-autoproxy/ >这句话之前一切都没问题,我已经测试过了,但是加了这句话准备用注解方式测试的时候,报错了~我完全是按照教程写的,实在找不到什么问题,求教各位大侠......
错误信息如下:
2013-5-17 20:38:02 org.springframework.context.support.AbstractApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@93d6bc: display name [org.springframework.context.support.ClassPathXmlApplicationContext@93d6bc]; startup date [Fri May 17 20:38:02 CST 2013]; root of context hierarchy
2013-5-17 20:38:02 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [aop-annotation-bean.xml]
2013-5-17 20:38:03 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactoryProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.aop.config.internalAutoProxyCreator]; root of factory hierarchy
...全文
364 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
anjx007 2013-05-21
  • 打赏
  • 举报
回复
唉,悲剧啊,犯了这么低级的错误~ @Before("maPointCut()") public void myBefore(){ System.out.println("-----执行前置处理-------"); } 的方法名引用错误:改为 @Before("myPointCut()") public void myBefore(){ System.out.println("-----执行前置处理-------"); }
anjx007 2013-05-18
  • 打赏
  • 举报
回复
谢谢楼上的朋友,但是,你说的问题,我之前是有配置的,代码示例如下: 这是业务测试类: package aop.annotation.service; import org.springframework.context.annotation.Scope; import org.springframework.stereotype.Service; @Service("deptSerivceImpl") @Scope("prototype") public class DeptSerivceImpl implements DeptService { public DeptSerivceImpl(){} public void delete() { try { Thread.sleep(200); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("删除部门"); } public void save() { try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("保存部门"); } } 这个是切面测试类: package aop.annotation.aspect; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component; import org.springframework.util.StopWatch; @Aspect @Component("timeHander") public class TimeHander { @Pointcut("bean (*Service)") public void myPointCut(){}; @Before("maPointCut()") public void myBefore(){ System.out.println("-----执行前置处理-------"); } @Around("myPointCut()") public Object handerTime(ProceedingJoinPoint pjp){ try { // 开始计时 StopWatch watch=new StopWatch(pjp.getTarget().getClass().getName()); watch.start(pjp.getSignature().getName()); Object obj=pjp.proceed(); // 停止计时 watch.stop(); System.out.println(watch.prettyPrint()); return obj; } catch (Throwable e) { // TODO Auto-generated catch block e.printStackTrace(); return null; }//执行目标 } } 请各位大虾再帮忙看下啊~
神探狄仁杰 2013-05-18
  • 打赏
  • 举报
回复
另外,不建议用spring2.5了。至少用3.0的吧。
神探狄仁杰 2013-05-18
  • 打赏
  • 举报
回复
示例代码:

@Component
@Aspect
public class LogAspect {}

<aop:aspectj-autoproxy />
<context:component-scan base-package="com.yourself is package.*" />

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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