ASPCTJ
2024-09-04 16:11:32
ublic interface ISomeService {
public void doSome(); public String dade();
}
public class SomeService implements ISomeService {
//核心业务
public void doSome(){
System.out.println("我们都要找到Java开发工作,薪资6,7,8,9,10K");
} public String dade() {
System.out.println("==================");
return "add";
} }
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*; /**
* Created by QiuShao on 2017/7/31.
*/
@Aspect
public class MyAspect {
/*前置增强*/
@Before(value = "execution(* *..spring17.*.*(..))")
public void before(){
System.out.println("前置增强");
} /*后置增强*/
@AfterReturning(value = "execution(* *..spring17.*.*(..))")
public void after(){
System.out.println("后置增强");
}
/*环绕增强*/
@Around(value = "execution(* *..spring17.*.*(..))")
public Object around(ProceedingJoinPoint proceed) throws Throwable {
System.out.println("环绕前");
Object result=proceed.proceed();
System.out.println("环绕后");
if(result!=null){
return result;
/*String str=(String)result;
return str.toUpperCase();*/
}else {
return null;
}
}
}
配置文件
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
">
<!--01.目标对象-->
<bean id="someService" class="cn.bdqn.spring17.SomeService"></bean> <!--02.增强 通知-->
<bean class="cn.bdqn.spring17.MyAspect"></bean> <aop:aspectj-autoproxy/> </beans>
单侧
// aspectj 注解
@Test
public void test011(){
ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContextspring15.xml");
ISomeService service = (ISomeService) ctx.getBean("someService");
service.doSome();
String aa= service.dade();
System.out.println(aa); }
最新文章
- Web jquery表格组件 JQGrid 的使用 - 7.查询数据、编辑数据、删除数据
- Freemark基本语法知识(转)
- cocos2dx游戏开发——微信打飞机学习笔记(二)——游戏框架
- paip.提升效率--批量变量赋值 “多元”赋值
- 3、使用Oracle Logminer同步Demo
- Linux系统如何查看CPU型号等
- SVN二次开发——让SVN、TSVN(TortoiseSVN)支持windows的访问控制模型、NTFS ADS(可选数据流、NTFS的安全属性)
- Map 根据value 排序
- 深入理解JVM(三)——配置参数
- Linux通配符应用详解
- 文本处理三剑客之awk(No.1)
- js代码跑马灯效果-----轮播图字效果!
- 前端入门5-CSS弹性布局flex
- frameset,iframe框架之间如何互相调用变量、函数
- win10 + VS2010 + OpenCV2.4.10重编译OpenCV开发环境搭建
- Kafka 0.10问题点滴
- Matlab、R向量与矩阵操作 z
- UnicodeDecodeError: &#39;ascii&#39; codec can&#39;t decode byte 0x9c in position 1: ordinal not in range(128)
- 把多个js函数绑定到onload时间处理函数上
- 基础笔记1(进制,浮点,递归,floor,round和ceil)