spring-aop的简单实例注解版

项目结构如图,基本的spring的配置就不在赘述
1.首先编写自定义的切面类
package org.wu.test;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Component
@Aspect
public class DIv {
@Pointcut("execution(* org.wu.test.WyzController.say(..))")
public void aspect(){
}
@Before("aspect()")
public void dobefore(){
System.out.println("开始");
}
@AfterReturning("aspect()")
public void doAfter(){
System.out.println("结束");
}
}
@Component:然组件扫描注入到spring容器管理
@Aspect 指定切面类
@Pointcut() 指定切入点
@Before("aspect()")前置通知
package org.wu.test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitterReturnValueHandler;
@Controller
public class WyzController {
@Autowired
private Wyz wyz;
@RequestMapping("/say")
public String say() throws Exception {
wyz.say();
return "";
}
}要操作的类,就是把切面的作用指定带这个类的say方法上
这就完成了一个很简单的aop应用实例
spring-aop的简单实例注解版的更多相关文章
- Spring AOP配置简单记录(注解及xml配置方式)
在了解spring aop中的关键字(如:连接点(JoinPoint).切入点(PointCut).切面(Aspact).织入(Weaving).通知(Advice).目标(Target)等)后进行了 ...
- Spring Boot 2.X(八):Spring AOP 实现简单的日志切面
AOP 1.什么是 AOP ? AOP 的全称为 Aspect Oriented Programming,译为面向切面编程,是通过预编译方式和运行期动态代理实现核心业务逻辑之外的横切行为的统一维护的一 ...
- Spring Boot 实战 —— MyBatis(注解版)使用方法
原文链接: Spring Boot 实战 -- MyBatis(注解版)使用方法 简介 MyBatis 官网 是这么介绍它自己的: MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过 ...
- Eclipse IDE下的Spring框架使用简单实例
Eclipse IDE下的Spring框架使用简单实例 1 准备Java jdk安装. Eclipse软件安装.根据系统安装32/64版本,选择Eclipse IDE for Java Develop ...
- Spring Boot整合MyBatis(非注解版)
Spring Boot整合MyBatis(非注解版),开发时采用的时IDEA,JDK1.8 直接上图: 文件夹不存在,创建一个新的路径文件夹 创建完成目录结构如下: 本人第一步习惯先把需要的包结构创建 ...
- Spring Security4.X 简单实例介绍
简介 本例子采用的是SpringMVC.SpringSecurity和Spring整合的简单使用 使用gradle搭建的项目(gradle比maven更加便捷),可以自行了解 web.xml配置 &l ...
- java代理课程测试 spring AOP代理简单测试
jjava加强课程测试代码 反射. 代理 .泛型.beanUtils等 项目源码下载:http://download.csdn.net/detail/liangrui1988/6568169 热身运动 ...
- Spring AOP中使用@Aspect注解 面向切面实现日志横切功能详解
引言: AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术.AOP是OOP的延续,是软件开发中的一 ...
- c# spring aop的简单例子
刚刚完成了一个c#的spring aop简单例子,是在mac下用Xamarin Studio开发的.代码如下: 接口 using System; using System.Collections.Ge ...
随机推荐
- Java自学手记——struts2
struts2框架 struts2是一种基于MVC模式的框架,是在struts1的基础上融合了xwork的功能. struts2框架预处理了一些功能: >请求数据自动封装, >文件上传的功 ...
- LCS 算法实现
动态规划算法 #include <iostream> #include <string.h> #include <algorithm> #include <m ...
- 你要clean Android Studio project 么
原文:http://tekeye.uk/android/export-android-studio-project 如果嫌复制出来的项目太多,可以用文后的批处理删除一些文件,Android studi ...
- PHP实现跨域解决方法
如果要实现跨域通过设置Access-Control-Allow-Origin来实现跨域. 例如:客户端的域名是client.runoob.com,而请求的域名是server.runoob.com. 如 ...
- 打造属于自己的支持版本迭代的Asp.Net Web Api Route
在目前的主流架构中,我们越来越多的看到web Api的存在,小巧,灵活,基于Http协议,使它在越来越多的微服务项目或者移动项目充当很好的service endpoint. 问题 以Asp.Net W ...
- 基本的传染病模型:SI、SIS、SIR及其Python代码实现
本文主要参考博客:http://chengjunwang.com/en/2013/08/learn-basic-epidemic-models-with-python/.该博客有一些笔误,并且有些地方 ...
- Aspose.words 书签定位
1. 简介 Aspose.words 可以在不使用 Microsoft.Word 的情况下生成.修改.转换.打印文档.不依赖office组件,这一点给我们提供了极大的便利性,可以简单的引入 DLL(D ...
- java封装性、继承性及关键字
方法的参数传递(重点.难点)1.形参:方法声明时,方法小括号内的参数 实参:调用方法时,实际传入的参数的值 2.规则:java中的参数传递机制:值传递机制 1)形参是基本数据类型的:将实参的值传递 ...
- 怎么调试nodejs restful API 以及API的Authorization
最近Nodejs,python越来越火了,同时也越来越多的人在用node写服务,可是怎么去调试服务呢?以及当你一个服务发布出去,怎么保证其安全性呢? 环境:linux unbuntu 语言:nodej ...
- Phpcms安装前后域名默认访问路径
一.安装前 phpcms下载后index.html文件内容如下图,在本地服务器配置项目虚拟域名后,访问域名后直接跳到:域名/install/install.php,然后出现安装界面. 二.安装之后 提 ...