spring开发_Annotation_AOP_Before增强处理

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; } }

"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http: http: http: http: http: ="com.b510.aspect,com.b510.service"> expression="org.aspectj.lang.annotation.Aspect" /> ="com.b510.service.impl.CatServiceBean">

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 我的兴趣爱好是吃,喝,睡觉

相关文章

这篇文章主要介绍了spring的事务传播属性REQUIRED_NESTED的原...
今天小编给大家分享的是一文解析spring中事务的传播机制,相...
这篇文章主要介绍了SpringCloudAlibaba和SpringCloud有什么区...
本篇文章和大家了解一下SpringCloud整合XXL-Job的几个步骤。...
本篇文章和大家了解一下Spring延迟初始化会遇到什么问题。有...
这篇文章主要介绍了怎么使用Spring提供的不同缓存注解实现缓...