Spring的AOP基于AspectJ的注解方式开发1
参考自黑马培训机构
创建项目,引入jar包

编写目标类,切面类并完成配置
package spring.day2_aop2;
/*
* 编写目标类
*/
public class OrderDao { public void save() {
System.out.println("orderDao的save方法已经执行......");
}
public void delete() {
System.out.println("orderDao的delete方法已经执行......");
}
public void update() {
System.out.println("orderDao的update方法已经执行......");
}
public void find() {
System.out.println("orderDao的find方法已经执行......");
} }
package spring.day2_aop2; /*
* 编写切面类
*/ public class MyAspect { public void checkPri() {
System.out.println("=============权限校验(前置通知)=============");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- ===============================引入aop开发的约束============================ -->
<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"> <!-- ====在注解文件里开启aop的开发===== -->
<aop:aspectj-autoproxy></aop:aspectj-autoproxy> <!-- 配置目标类 -->
<bean id="orderDao" class="spring.day2_aop2.OrderDao"></bean> <!-- 配置切面类 -->
<bean id="myAspect" class="spring.day2_aop2.MyAspect"></bean> </beans>
在配置文件中开启aop的注解开发

使用注解对目标类进行增强
package spring.day2_aop2; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; /*
* 编写切面类
*/
@Aspect
public class MyAspect { @Before(value="execution(* spring.day2_aop2.OrderDao.save(..))")
public void checkPri() {
System.out.println("=============权限校验(前置通知)=============");
}
}
编写测试类并完成测试
package spring.day2_aop2; import javax.annotation.Resource; import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /*
* 编写测试类
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext5.xml")
public class SpringDemo1 { @Resource(name="orderDao")
private OrderDao orderDao; @Test
public void demo1() {
orderDao.save();
orderDao.delete();
orderDao.update();
orderDao.find();
}
}

Spring的AOP基于AspectJ的注解方式开发1的更多相关文章
- Spring的AOP基于AspectJ的注解方式开发2
参考自黑马培训机构 上一篇博客提到了在配置文件中开启aop的注解开发,以及简单使用了@Before,@Aspect 这是为了告诉spring为前置通知和切面类 接下来介绍aop的注解的通知类型,和切入 ...
- Spring的AOP基于AspectJ的注解方式开发3
上上偏博客介绍了@Aspect,@Before 上篇博客介绍了spring的AOP开发的注解通知类型:@Before,@AfterThrowing,@After,@AfterReturning,@Ar ...
- 基于AspectJ的注解方式进行AOP开发
-------------------siwuxie095 基于 AspectJ 的注解方式进行 AOP 开发 ...
- spring AOP (使用AspectJ的注解方式 的aop实现) (6)
目录 一.在 Spring 中启用 AspectJ 注解支持 二.AspectJ 支持 5 种类型的通知注解: 2.1.使用之前的 计算器接口和实现类 ArithmeticCalculator.jav ...
- AOP——基于AspectJ的注解来实现AOP操作
1.使用注解方式实现AOP操作 第一步:创建对象 <!-- 创建对象 --> <bean id="book" class="com.bjxb.aop.B ...
- Spring框架的事务管理之基于AspectJ的注解方式(重点掌握,最简单的方式)
1. 步骤一:恢复转账的开发环境(具体开发环境实现见:https://www.cnblogs.com/wyhluckdog/p/10137283.html)2. 步骤二:applicationCont ...
- 【AOP】操作相关术语---【Spring】的【AOP】操作(基于aspectj的xml方式)
[AOP]操作相关术语 Joinpoint(连接点):类里面哪些方法可以被增强,这些方法称为连接点. Pointcut(切入点):在类里面可以有很多的方法被增强,比如实际操作中,只是增强了类里面add ...
- day39-Spring 08-Spring的AOP:基于AspectJ的注解
基于AspectJ的注解的开发要重点掌握. 这些表达式肯定要应用在我们的某些个增强上. 学习AspectJ也是两种形式:一种是XML,一种是注解.AspectJ的增强,就是那些通知的类型.Aspect ...
- Spring_AOP基于AspectJ的注解开发&JDBC的模板使用&事务管理(学习笔记3)
一:AOP基于AspectJ的注解开发 1,简单的实例: 1)引入相应的jar包 2)在配置文件里引入相关约束 <beans xmlns="http://www.springfra ...
随机推荐
- .net里的ref、out、params参数。
1.ref參數 class Program { static void Main(string[] args) { int a = 10; ...
- Response.Redirect()和Response.RedirectPermanent()区别
备注:这里我用到了Response.RedirectPermanent()用于做301跳转, 如:我希望访问网站的url访问地址为:http://m.shop/abc.html ,用户输入的访问地址: ...
- [转]usdt omnicore testnet 测试网络
本文转自:https://www.jianshu.com/p/417c280b8f9f Testnet 模式允许 omni core 运行在比特币测试链上,用于安全测试. 为了在 testnet 上收 ...
- 《Office 365开发入门指南教程》正式上线,限时优惠和邀请分享推广
我很高兴地通知大家,<Office 365 开发入门指南教程>已经正式在网易云课堂上线,你可以通过直接访问 https://aka.ms/office365devlesson 这个短地址 ...
- [PHP] PHP在CLI环境下的错误日志
1.display_errors = Off;//控制php是否输出错误;在生产环境中输出会泄露敏感信息;建议记录错误而不是将它们发送到STDOUToff :不显示任何错误;stderr :向STDE ...
- cas单点登录
一般一家企业内部会有多个业务系统,多个系统相互协作,但每个系统都需要登陆密码,比如:权限系统,发布系统,配置系统,邮件系统等,用户使用每个系统都需要登陆操作,使用起来比较繁琐,工作效率低下.此时就需要 ...
- spring-framework-中文文档二:Bean概述
Spring IoC容器管理一个或多个bean.这些bean是使用您提供给容器的配置元数据创建的,例如,以XML <bean/>定义的形式 . 在容器本身中,这些bean定义被表示为 Be ...
- 【资料】Mac OS X 10.9虚拟机镜像及tools
原文链接 http://bbs.itheima.com/thread-141793-1-1.html 1.首先解压文件,两个同时选中,右键进行解压. 2.打开虚拟机VMware workstation ...
- JavaScript Array常用属性和方法
Array的length属性可以通过赋值改变,但这样会导致Array原有的大小发生改变. var a = ["I", "Love", "You&quo ...
- BZOJ 2463: [中山市选2009]谁能赢呢?(智商)
Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3110 Solved: 2250[Submit][Status][Discuss] Descript ...