com.b510.app.test; org.springframework.context.ApplicationContext; org.springframework.context.support.ClassPathXmlApplicationContext; com.b510.service.AnimalService; SpringTest { main(String[] args) { ApplicationContext act = ClassPathXmlApplicationContext("beans.xml"); AnimalService cat = (AnimalService) act.getBean("cat"); cat.printResult(); cat.printHobby(); } }
com.b510.aspect; org.aspectj.lang.annotation.Aspect; org.aspectj.lang.annotation.Before; @Aspect MyBeforeAdvice { i = 0; @Before("execution(* com.b510.service.impl.*.*(..))") getVisits() { System.out.println("自定义切面MyBeforeAdvice类的getVisits()方法的执行此数为" + (++i)); } }
com.b510.service; AnimalService { printResult(); printHobby(); }
com.b510.service.impl; org.springframework.stereotype.Component; com.b510.service.AnimalService; @Component CatServiceBean AnimalService { String name; String hobby; String getHobby() { hobby; } String getName() { name; } @Override printHobby() { System.out.println("我的兴趣爱好是" + getHobby()); } @Override printResult() { System.out.println("大家好,我是" + getName()); } setHobby(String hobby) { .hobby = hobby; } setName(String name) { .name = name; } }
"
2012-3-13 20:33:46 org.springframework.context.support.AbstractApplicationContext prepareRefresh 信息: Refreshing org.springframework.context.support.ClasspathXmlApplicationContext@c1b531: display name [org.springframework.context.support.ClasspathXmlApplicationContext@c1b531]; startup date [Tue Mar 13 20:33:46 CST 2012]; root of context hierarchy 2012-3-13 20:33:46 org.springframework.beans.factory.xml.XmlBeanDeFinitionReader loadBeanDeFinitions 信息: Loading XML bean deFinitions from path resource [beans.xml] 2012-3-13 20:33:56 org.springframework.context.support.AbstractApplicationContext obtainFreshbeanfactory 信息: Bean factory application context [org.springframework.context.support.ClasspathXmlApplicationContext@c1b531]: org.springframework.beans.factory.support.DefaultListablebeanfactory@12a3722 2012-3-13 20:33:56 org.springframework.beans.factory.support.DefaultListablebeanfactory preInstantiateSingletons 信息: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListablebeanfactory@12a3722: defining beans [myBeforeAdvice,catServiceBean,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalrequiredAnnotationProcessor,org.springframework.aop.config.internalAutoproxyCreator,cat]; root of factory hierarchy 自定义切面MyBeforeAdvice类的getVisits()方法的执行此数为1 大家好,我是加菲 自定义切面MyBeforeAdvice类的getVisits()方法的执行此数为2 我的兴趣爱好是吃,喝,睡觉
搜索com.b510.service.impl包下的所有类及其类的方法,作为本方法的切入点(Jionpoint)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。