加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

spring开发_Annotation_AOP_Before增强处理

发布时间:2020-12-15 01:52:40 所属栏目:大数据 来源:网络整理
导读:com.b510.app.test; org.springframework.context.ApplicationContext; org.springframework.context.support.ClassPathXmlApplicationContext; com.b510.service.AnimalService; SpringTest { main(String[] args) { ApplicationContext act = ClassPathXml

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读