AOP实现方式3——通过<aop:config>来配置(纯POJO切面)
来源:互联网 发布:桐乡淘宝客服招聘信息 编辑:程序博客网 时间:2024/06/11 01:02
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
- 第一章.对象导论
- Anaconda+Tensorflow环境安装与配置
- AOP实现方式2——通过AspectJ提供的注解实现AOP
- CentOS7(linux)中ssh服务配置
- 【机器学习】决策树
- AOP实现方式3——通过<aop:config>来配置(纯POJO切面)
- 谈谈单例模式(一)
- CentOS 6 升级python2.66 到2.78 yum 无法使用解决方案
- C++标准库中bitset类的用法
- springmvc-异常的处理
- 第二章.一切都是对象
- PAT 1077. 互评成绩计算 (20)
- iOS编译libx264+libfdk-aac+FFmpeg
- Android混淆详解