Spring Aop的理解和简单实现
- AOP的应用:
- Xml配置 这里的xml配置引入了aop的xsd语法约束。另外加入的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";
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-2.5.xsd
- http://www.springframework.org/schema/aop
- http://www.springframework.org/schema/aop/spring-aop-2.5.xsd"; >
- <context:annotation-config/>
- <!-- 配置容器资源扫描的包 -->
- <context:component-scan base-package="com.spring" />
- <!-- 自动产生代理,内部实现是用AspectJ实现。可以使用aspectj的注解产生代理 -->
- <aop:aspectj-autoproxy />
- </beans>

- import org.springframework.stereotype.Component;
- import com.spring.dao.UserDao;
- @Component("userService")
- public class UserServiceImpl implements UserService{
- private UserDao userDao;
- public void setUserDao(UserDao userDao) {
- this.userDao = userDao;
- }
- //在下面方法前面加逻辑
- public void HelloWorld(){
- System.out.println("helloworld");
- }
- }
- package com.spring.aop;
- import org.aspectj.lang.annotation.Aspect;
- import org.aspectj.lang.annotation.Before;
- import org.springframework.stereotype.Component;
- //声明切面
- @Aspect
- //加入Spring管理容器
- @Component("LogInterceptor")
- public class LogInterceptor {
- //指定织入的方法。
- @Before("execution(public void com.spring.service.UserServiceImpl.HelloWorld())")
- public void BeforeMethod(){
- System.out.println("method start!");
- }
- }
- 测试aop的织入:
- public class SpringTest {
- @Test
- public void test01() {
- BeanFactory applicationContext = new ClassPathXmlApplicationContext(
- "beans.xml");
- UserService user = (UserService) applicationContext.getBean("userService");
- user.HelloWorld();
- }
- }
Cannot proxy target class because CGLIB2 is not available.Add CGLIB to the class path or specify proxy interfaces
Spring Aop的理解和简单实现的更多相关文章
- Spring AOP深入理解之拦截器调用
Spring AOP深入理解之拦截器调用 Spring AOP代理对象生成回想 上一篇博客中:深入理解Spring AOP之二代理对象生成介绍了Spring代理对象是怎样生成的,当中重点介绍了JDK动 ...
- Spring AOP初级——入门及简单应用
在上一篇<关于日志打印的几点建议以及非最佳实践>的末尾提到了日志打印更为高级的一种方式——利用Spring AOP.在打印日志时,通常都会在业务逻辑代码中插入日志打印的语句,这实际上是 ...
- 基于Spring aop写的一个简单的耗时监控
前言:毕业后应该有一两年没有好好的更新博客了,回头看看自己这一年,似乎少了太多的沉淀了.让自己做一个爱分享的人,好的知识点拿出来和大家一起分享,一起学习. 背景: 在做项目的时候,大家肯定都遇到对一些 ...
- Spring AOP详解及简单应用
Spring AOP详解 一.前言 在以前的项目中,很少去关注spring aop的具体实现与理论,只是简单了解了一下什么是aop具体怎么用,看到了一篇博文写得还不错,就转载来学习一下,博文地址: ...
- spring aop 的理解
spring aop的相关概念(所有的概念都是为了生成代理类这个过程所需要的信息的抽象): 1.Targer:目标对象.被代理的对象. 2.Advice:增强/通知.就是为目标对象扩展的功能.分为前置 ...
- 使用Spring AOP 实现日志管理(简单教程)
有时候,我们在做项目时会遇到这样的需求: 给XXX.java中的所有方法加上指定格式的日志输出. 针对这种指定类.或者指定方法进行共性操作的功能,我们完全可以使用Spring AOP来实现. 本文使用 ...
- Spring AOP的理解和使用
AOP是Spring框架面向切面的编程思想,AOP采用一种称为“横切”的技术,将涉及多业务流程的通用功能抽取并单独封装,形成独立的切面,在合适的时机将这些切面横向切入到业务流程指定的位置中. 掌握AO ...
- Spring AOP概念理解
1.我所知道的aop 初看aop,上来就是一大堆术语,而且还有个拉风的名字,面向切面编程,都说是OOP的一种有益补充等等.一下子让你不知所措,心想着:怪不得很多人都和我说aop多难多难.当我看进去以后 ...
- Spring AOP的理解(通俗易懂)。
转载 原文链接:http://www.verydemo.com/demo_c143_i20837.html 这种在运行时,动态地将代码切入到类的指定方法.指定位置上的编程思想就是面向切面的编程. 1. ...
随机推荐
- DDOS hulk,rudy
HULK (HTTP Unbearable Load King) HULK HULK是另一个DOS攻击工具,这个工具使用UserAgent的伪造,来避免攻击检测,可以通过启动500线程对目标发起高频率 ...
- HTML标签_head标签
HTML标签分为两种,自闭合标签和主动闭合标签:没有另一半 自动闭合标签,有另一半叫主动闭合标签. 自动闭合标签,只有开头没有结尾,即没有另一半:如<meta charset="UTF ...
- 【Echarts】图表用echarts【待完善】
echarts是做数据统计. ECharts,一个纯 Javascript 的图表库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8/9/10/11,Chrome,Firefox ...
- MySQL找出锁等待
1.服务器级别的锁等待 可以通过show processlist看到等待锁的线程id,但是无法知道究竟哪个线程持有锁 可以通过mysqladmin debug 相关等待锁的线程以及谁持有锁可以在错误日 ...
- mysql 操作sql语句 操作数据表
#2. 操作文件 先切换到文件夹下:use db1 查看当前所在的数据库 mysql> select database(); +------------+ | database() | +--- ...
- string、const char*、 char* 、char[]相互转换(待整理)
string.const char*. char* .char[]相互转换(全) https://blog.csdn.net/rongrongyaofeiqi/article/details/5244 ...
- django的serializers
views.py # get所需的 from snippets.serializers import SnippetSerializer from rest_framework.views impor ...
- [py]一些搜集到的问题
过滤爬虫爬取下来的关键字 v1,来不及了,先上车 content = ['哈士奇', '二哈', '哈士奇图片','哈士奇图片', '哈士奇美丽价格', '哈士奇是个大傻逼', '猫咪图片', '猫咪 ...
- hdu3339In Action(最短路+01背包)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=259#problem/H Description Since 1945, whe ...
- 主成分分析(PCA)算法,K-L变换 角度
主成分分析(PCA)是多元统计分析中用来分析数据的一种方法,它是用一种较少数 量的特征对样本进行描述以达到降低特征空间维数的方法,它的本质实际上是K-L变换.PCA方法最著名的应用应该是在人脸识别中特 ...