AOP实现方式3——通过<aop:config>来配置(纯POJO切面)
来源:互联网 发布:mysql 查看梭镖 编辑:程序博客网 时间:2024/06/06 07:35
1.定义接口Perform
package com.show;/** * Created by kenneth on 2017/4/6. */public interface Perform { void sing();}
2.接口Perform的实现类Boy
package com.show;/** * Created by kenneth on 2017/4/6. */public class Boy implements Perform { @Override public void sing() { System.out.println("男孩在唱歌"); }}
3.定义通知PerformHelper
package com.show;/** * Created by kenneth on 2017/4/6. */public class PerformHelper { public void beforePerform() { System.out.println("表演之前要整理衣服"); } public void afterPerform() { System.out.println("表演之后要行礼"); }}
4.Spring配置文件
<?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.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!--目标对象--> <bean id="boy" class="com.show.Boy"/> <!--切面--> <bean id="performHelper" class="com.show.PerformHelper"/> <!--配置切入点--> <aop:config> <aop:pointcut id="pointcut" expression="execution(public * *..Perform.sing(..))"/> <aop:aspect ref="performHelper"> <aop:before method="beforePerform" pointcut-ref="pointcut"/> <aop:after method="afterPerform" pointcut-ref="pointcut"/> </aop:aspect> </aop:config></beans>
5.测试类
package com.show;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;/** * Created by kenneth on 2017/4/6. */public class Test { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("ApplicationContext.xml"); Perform performer = (Perform) context.getBean("boy"); performer.sing(); }}
6.测试结果
四月 06, 2017 2:02:38 下午 org.springframework.context.support.ClassPathXmlApplicationContext prepareRefresh
信息: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@533ddba: startup date [Thu Apr 06 14:02:38 CST 2017]; root of context hierarchy
四月 06, 2017 2:02:38 下午 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
信息: Loading XML bean definitions from class path resource [ApplicationContext.xml]
表演之前要整理衣服
男孩在唱歌
表演之后要行礼
0 0
- AOP实现方式3——通过<aop:config>来配置(纯POJO切面)
- AOP实现方式3——通过<aop:config>来配置(纯POJO切面)
- Spring纯POJO切面实现AOP
- Spring面向切面编程——Spring实现AOP方式——通过Spring API实现
- Spring面向切面编程——Spring实现AOP方式——通过注解实现
- Spring整理11 -- 面对切面(AOP)1 -- 注解配置的方式实现AOP
- Spring整理11 -- 面对切面(AOP)1 -- 注解配置的方式实现AOP
- Spring 通过注解方式实现AOP切面编程
- Spring 通过Spring AOP 方式来实现AOP
- 【Spring】纯java实现AOP切面编程
- Spring AOP(三)——通过@AspectJ注解切面
- <七>AOP面向切面——配置bean.xml文件方式声明切面(附源码)
- Spring AOP学习笔记(4):AOP切面优先级&切面表达式重用&xml配置方式
- Spring-通过xml配置文件实现切面(AOP)
- 注解方式实现AOP切面编程
- 注解方式实现aop事务切面
- 【框架】[Spring]纯Java的方式实现AOP切面(拦截)技术
- Spring学习笔记 —— AOP(面向切面编程) 之使用ProxyFactoryBean实现AOP
- 奇葩版Flappy Bird,HTML5 Flappy游戏源码下载
- 【剑指offer】无聊的1+2+...+n
- leetcode146. LRU Cache
- 为什么你的问题总是解决的一团糟?
- C++中的左值与右值(二
- AOP实现方式3——通过<aop:config>来配置(纯POJO切面)
- cocos2dx《我叫MT》源码和资源破解下载
- hibernate 连 oracle 没有主键怎么办
- jstat详解
- HTML内联元素
- Java代码Base64加密解密使用
- Django cache简单实现
- 从4行代码看右值引用
- 基于DragonBoard 410c的遥控炮台五之硬件DIY