spring AOP详解之--前置增强 (MethodBeforeAdvice)
来源:互联网 发布:php 上传工具 编辑:程序博客网 时间:2024/06/03 11:16
这里举一个简单的demo
先写一个接口 Hello.java
最后的xml文件的配置
再编写一个测试类TestHello.java
这就是一个完整的前置增强的例子,后面我还会陆续介绍其他几种增强。谢谢
package niit.soft1521;/** * Created by lenovo-pc on 2017/3/13. */public interface Hello { String sayHello();}在写一个接口的实施类HelloImpl.java
package niit.soft1521;/** * Created by lenovo-pc on 2017/3/13. */public class HelloImpl implements Hello { @Override public String sayHello() { return "hello ,welcom !"; }}再写一个前置增强的类MyBeforeMethod.java
package niit.soft1521;/** * Created by lenovo-pc on 2017/3/13. * 用户自定义的前置增强类 */public class MybeforeMethod { public void BeforeMethod(){ System.out.println("this is a before method !"); }}
最后的xml文件的配置
<?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="hello" class="niit.soft1521.HelloImpl"></bean> <bean id="MyBefore" class="niit.soft1521.MybeforeMethod"></bean> <aop:config> <aop:aspect id="before" ref="MyBefore"> <aop:pointcut id="MyPointCut" expression="execution(* niit.soft1521.*.*(..))"></aop:pointcut> <aop:before method="BeforeMethod" pointcut-ref="MyPointCut"></aop:before> </aop:aspect> </aop:config></beans>
再编写一个测试类TestHello.java
package niit.soft1521;import org.springframework.context.ApplicationContext;import org.springframework.context.support.ClassPathXmlApplicationContext;/** * Created by lenovo-pc on 2017/3/13. */public class TestHello { public static void main(String[] args) { ApplicationContext applicationContext =new ClassPathXmlApplicationContext("ApplicationContext.xml"); Hello hello=(Hello)applicationContext.getBean("hello"); System.out.println(hello.sayHello()); }}
这就是一个完整的前置增强的例子,后面我还会陆续介绍其他几种增强。谢谢
0 0
- spring AOP详解之--前置增强 (MethodBeforeAdvice)
- spring-aop之MethodBeforeAdvice实现
- Spring AOP(1)- 前置增强 实现
- Spring-AOP 通过配置文件实现 前置增强
- 关于配置spring AOP中的前置通知MethodBeforeAdvice出现的异常
- spring AOP 前置增强,后置增强小Demo
- Spring AOP Advice接口-MethodBeforeAdvice+AfterReturningAdvice
- Spring之AOP(二)---前置通知
- 七.Spring AOP 之增强
- Spring AOP之增强介绍
- Spring AOP之增强(aspectj)
- Spring-------- 增强(前置,后置,异常,环绕)
- spring(四)前置增强
- Spring学习(二十五)Spring AOP之增强介绍
- Spring的aspectj的AOP操作(前置增强 后置增强 环绕)
- Spring AOP-前置通知
- Spring--AOP-前置通知
- Spring MethodBeforeAdvice
- GoogLeNet Inception V1:Going deeper with convolutions论文笔记
- 打开一个已经存在于工作空间的android项目
- 直接将datatable插入数据库中
- Java选择排序算法
- 日常生活 -- 数据结构与算法告一段落
- spring AOP详解之--前置增强 (MethodBeforeAdvice)
- 设计模式之单例模式
- 使用Spring的@Scheduled实现定时任务
- MyEclipse破解版+tomcat安装+jdk
- [Python 爬虫之路4] 使用selenium爬取知乎任意一个问题下,所有回答中的图片
- Android TextView 添加下划线的几种方式
- Spring Web MVC基础的一个小实例
- 详解google Chrome浏览器(理论篇)
- Android框架/系统服务是怎样管理第三方Search数据源的?