参考自黑马培训机构

创建项目,引入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的更多相关文章

  1. Spring的AOP基于AspectJ的注解方式开发2

    参考自黑马培训机构 上一篇博客提到了在配置文件中开启aop的注解开发,以及简单使用了@Before,@Aspect 这是为了告诉spring为前置通知和切面类 接下来介绍aop的注解的通知类型,和切入 ...

  2. Spring的AOP基于AspectJ的注解方式开发3

    上上偏博客介绍了@Aspect,@Before 上篇博客介绍了spring的AOP开发的注解通知类型:@Before,@AfterThrowing,@After,@AfterReturning,@Ar ...

  3. 基于AspectJ的注解方式进行AOP开发

    -------------------siwuxie095                                     基于 AspectJ 的注解方式进行 AOP 开发         ...

  4. spring AOP (使用AspectJ的注解方式 的aop实现) (6)

    目录 一.在 Spring 中启用 AspectJ 注解支持 二.AspectJ 支持 5 种类型的通知注解: 2.1.使用之前的 计算器接口和实现类 ArithmeticCalculator.jav ...

  5. AOP——基于AspectJ的注解来实现AOP操作

    1.使用注解方式实现AOP操作 第一步:创建对象 <!-- 创建对象 --> <bean id="book" class="com.bjxb.aop.B ...

  6. Spring框架的事务管理之基于AspectJ的注解方式(重点掌握,最简单的方式)

    1. 步骤一:恢复转账的开发环境(具体开发环境实现见:https://www.cnblogs.com/wyhluckdog/p/10137283.html)2. 步骤二:applicationCont ...

  7. 【AOP】操作相关术语---【Spring】的【AOP】操作(基于aspectj的xml方式)

    [AOP]操作相关术语 Joinpoint(连接点):类里面哪些方法可以被增强,这些方法称为连接点. Pointcut(切入点):在类里面可以有很多的方法被增强,比如实际操作中,只是增强了类里面add ...

  8. day39-Spring 08-Spring的AOP:基于AspectJ的注解

    基于AspectJ的注解的开发要重点掌握. 这些表达式肯定要应用在我们的某些个增强上. 学习AspectJ也是两种形式:一种是XML,一种是注解.AspectJ的增强,就是那些通知的类型.Aspect ...

  9. Spring_AOP基于AspectJ的注解开发&JDBC的模板使用&事务管理(学习笔记3)

    一:AOP基于AspectJ的注解开发 1,简单的实例: 1)引入相应的jar包 ​ 2)在配置文件里引入相关约束 <beans xmlns="http://www.springfra ...

随机推荐

  1. C#集合。

    集合命名空间: using system.collections. 非泛型集合 using system.collections.Generic.  泛型集合 为什么要用集合: 1.数组一旦声明长度就 ...

  2. SQL--server事物

    事物 特点: 1.原子性:事物必须是一个自动工作的单元, 2.一致性:事物结束的时候,所有内部数据都是正确的 3.隔离性:并发多个事物时,各个事物不干涉内部数据,处理的都是另外一个事物处理之前或之后的 ...

  3. [PHP] swoole的安装和简单使用

    1. pecl install swoole 开启http2支持需要的依赖库:apt-get install nghttp2 开启的几个参数: enable sockets supports? [no ...

  4. mybatis_03_ mapper代理方式实现MyBatis的Dao编写

    不是用mapper代理方式也能够实现,但是不推荐 Mapper代理的开发方式,程序员只需要编写mapper接口(相当于dao接口)即可.Mybatis会自动的为mapper接口生成动态代理实现类. 不 ...

  5. Elastic-Job-分布式调度解决方案

    Elastic-Job是一个分布式调度解决方案,由两个相互独立的子项目Elastic-Job-Lite和Elastic-Job-Cloud组成. Elastic-Job-Lite定位为轻量级无中心化解 ...

  6. 自己用HashMap来模拟一个Session缓存(简易版)

    本文记录:Hibernate中一级缓存的特点. 一级缓存的细节什么操作会向一 1.级缓存放入数据 save,update,saveOrUpdate,load,get,list,iterate,lock ...

  7. Fzreo matlab

    fzero Root of nonlinear function collapse all in page Syntax x = fzero(fun,x0) example x = fzero(fun ...

  8. webpack4 系列教程(十四):Clean Plugin and Watch Mode

    作者按:因为教程所示图片使用的是 github 仓库图片,网速过慢的朋友请移步<webpack4 系列教程(十四):Clean Plugin and Watch Mode>原文地址.更欢迎 ...

  9. crontab工具安装和检查

    什么是crontab?crontab 是一个用于设置周期性执行任务的工具 重启crond守护进程 systemctl restart crond 查看当前crond状态 systemctl statu ...

  10. 小tips:JS严格模式(use strict)下不能使用arguments.callee的替代方案

    在函数内部,有两个特殊的对象:arguments 和 this.其中, arguments 的主要用途是保存函数参数, 但这个对象还有一个名叫 callee 的属性,该属性是一个指针,指向拥有这个 a ...