【核心核心】8.Spring【AOP】注解方式
1.引入jar包
sprig框架基础包+JUntil整合包+日志包+AOP包

spring的传统AOP的开发的包
spring-aop-4.2.4.RELEASE.jar
com.springsource.org.aopalliance-1.0.0.jar
aspectJ的开发包
com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar
spring-aspects-4.2.4.RELEASE.jar
2.引入配置文件(AOP约束,注解约束)
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">
</beans>
3.创建实现类
public interface UserService {
public void save();
public void update();
public void delete();
}
@Service(value="userService")
public class UserServiceImpl implements UserService {
@Override
public void save() {
// TODO Auto-generated method stub
System.out.println("业务层:保存客户..");
}
@Override
public void update() {
// TODO Auto-generated method stub
System.out.println("业务层:更新客户..");
}
@Override
public void delete() {
// TODO Auto-generated method stub
System.out.println("业务层:删除客户..");
}
}
4.将实现类托管于Spring注解方式

5.创建切面类
public class MyAspectAnn {
public void log(){
System.out.println("前置通知..");
}
public void arround(ProceedingJoinPoint joinPoint){
System.out.println("环绕通知1..");
System.out.println("环绕通知2..");
}
public void after(){
System.out.println("后置通知..");
}
}
6.将切面类托管于Spring

7.定义切面类方法的切入点

8.在配置文件中开启自动代理,并扫描注解
<!-- 扫描注解 -->
<context:component-scan base-package="com.spring.demo1"/>
<!-- 开启自动代理 -->
<aop:aspectj-autoproxy/>
9.编写测试代码
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:applicationContext.xml")
public class Demo1 {
@Resource(name="userService")
private UserService userService;
@Test
public void m01(){
System.out.println("=======================");
userService.save();
System.out.println("=======================");
userService.update();
System.out.println("=======================");
userService.delete();
System.out.println("=======================");
}
}
效果:

【核心核心】8.Spring【AOP】注解方式的更多相关文章
- spring aop注解方式与xml方式配置
注解方式 applicationContext.xml 加入下面配置 <!--Spring Aop 启用自动代理注解 --> <aop:aspectj-autoproxy proxy ...
- 转:Spring AOP 注解方式实现的一些“坑”
使用过Spring AOP的注解方式实现,也入过不少坑,现在做一下记录,希望有同样需求的朋友可以少走弯路 使用之前还是先过一下官方文档吧,至少可以少走弯路,不用担心英文读不懂,其实只看代码例子就能理解 ...
- Spring Aop 注解方式参数传递
v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VM ...
- (转)使用Spring的注解方式实现AOP的细节
http://blog.csdn.net/yerenyuan_pku/article/details/52879669 前面我们已经入门使用Spring的注解方式实现AOP了,现在我们再来学习使用Sp ...
- (转)使用Spring的注解方式实现AOP入门
http://blog.csdn.net/yerenyuan_pku/article/details/52865330 首先在Eclipse中新建一个普通的Java Project,名称为spring ...
- Spring系列之aAOP AOP是什么?+xml方式实现aop+注解方式实现aop
Spring系列之aop aop是什么?+xml方式实现aop+注解方式实现aop 什么是AOP? AOP为Aspect Oriented Programming 的缩写,意识为面向切面的编程,是通过 ...
- 来一手 AOP 注解方式进行日志记录
系统日志对于定位/排查问题的重要性不言而喻,相信许多开发和运维都深有体会. 通过日志追踪代码运行状况,模拟系统执行情况,并迅速定位代码/部署环境问题. 系统日志同样也是数据统计/建模的重要依据,通过分 ...
- Spring AOP配置方式
AOP 面向切面编程,允许在 java 应用中的方法调用的前后做一些处理. 本文通过实例介绍两种主要的Spring AOP 配置方式:xml 方式配置,注解方式配置 XML 方式配置 1. 项目包类结 ...
- Spring AOP注解为什么失效?90%Java程序员不知道
使用Spring Aop注解的时候,如@Transactional, @Cacheable等注解一般需要在类方法第一个入口的地方加,不然不会生效. 如下面几种场景 1.Controller直接调用Se ...
- Spring AOP注解形式简单实现
实现步骤: 1:导入类扫描的注解解析器 命名空间:xmlns:context="http://www.springframework.org/schema/context" xsi ...
随机推荐
- 本地git安装完成之后,从远程git服务器上面下载代码。报错SSL certificate problem:self signed certificate in certificate chain。
解决方案:打开git的控制端黑窗口,输入: git config --global http.sslVerify false 点击Entry之后,就会去掉git的ssl验证. 然后就可以正常的下载代码 ...
- 使用Element的upload上传组件,不使用action属性上传
1.需要实现的效果如下图,在点击提交的时候再提交file数据,和其他数据统一上传,我把file转换成了base64的格式,可以再上传之前显示缩略图 2.代码分析 action属性值为"#&q ...
- Java 多线程 - 死锁deadlock产生原因+避免方法
ref: java中产生死锁的原因及如何避免 https://blog.csdn.net/m0_38126177/article/details/78587845 java如何避免死锁 http:// ...
- 校园商铺-2项目设计和框架搭建-8升级mysql驱动相关的配置以支持mysql8
1.如何升级驱动 1.1步骤: a 确保当前程序能正常访问数据库 b 更新mysql驱动重新运行程序进行校验 maven依赖https://mvnrepository.com/artifact/mys ...
- 阿里云启动视频云V5计划,全面赋能生态合作伙伴
9月25 - 27日,主题为数·智的2019云栖大会在杭州举行.在第三天的智能视频云专场中,阿里云研究员金戈首次对外发布视频云V5计划,释放视频IT基础设施红利,赋能生态合作伙伴,共促大视频产业发展. ...
- Duilib中各个类的简单介绍
DirectUI意为直接在父窗口上绘图(Paint on parent dc directly).即子窗口不以窗口句柄的形式创建(windowless),只是逻辑上的窗口,绘制在父窗口之上.微软的“D ...
- sprintf、fprintf和printf这三个函数有什么区别?
都是把格式好的字符串输出,只是输出的目标不一样:1 printf,是把格式字符串输出到标准输出(一般是屏幕,可以重定向).2 sprintf,是把格式字符串输出到指定字符串中,所以参数比printf多 ...
- 关于Ubuntu锁屏后,无法输入密码
屏幕锁定后字母密码无法输入,数字可以,切换用户然后可以正常输入密码登陆. 是输入法的事,锁屏界面依然是中文输入法,然后输入字母之后先不会显示然后加上数字后是汉字密码不对. 切换输入法到英文,就可以正常 ...
- NYOJ-109 数列转换 AC 分类: NYOJ 2014-12-01 00:54 84人阅读 评论(0) 收藏
守恒法的问题,表示,刚刚看了一点点 #include <iostream> #include <cstring> #include <cstdio> #includ ...
- 18-4-bind
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...