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); }

ASPCTJ的更多相关文章

  1. [Spring框架]Spring AOP基础入门总结二:Spring基于AspectJ的AOP的开发.

    前言: 在上一篇中: [Spring框架]Spring AOP基础入门总结一. 中 我们已经知道了一个Spring AOP程序是如何开发的, 在这里呢我们将基于AspectJ来进行AOP 的总结和学习 ...

  2. 11Spring_AOP编程(AspectJ)_概述

    AspectJ 是一个框架 (第三方AOP框架 ),提供切面编程 ,编写一个Aspect 支持多个Advice和多个PointCut .对比前一种提到的传统的Aop编程,AspctJ更加的常用.Asp ...

  3. Spring基于AspectJ的AOP的开发——注解

    源码:https://gitee.com/kszsa/dchart 一, AspectJ的概述: AspectJ是一个面向切面的框架,它扩展了Java语言.AspectJ定义了AOP语法所以它有一个专 ...

  4. spring中AspectJ的使用

    目录 AspectJ: AOP术语 通知的类型 切入点表达式 基于xml的AspectJ编程 导入jar包 定义切面类 引入约束 AOP配置 基于注解的AspectJ编程 AspectJ: 什么是AO ...

随机推荐

  1. ambari 维护模式及reset API 操作

    Ambari 的维护模式(Maintenance Mode)介绍 Ambari 提供的 Maintenance Mode,是为了让用户在调试或者维护 Service 的时候,抑制不必要的告警(Aler ...

  2. Win 10 无法打开内核设备“\\.\Global\vmx86”

    Win 10操作系统, VMWareWorkstation10 无法打开内核设备“\\.\Global\vmx86”: 系统找不到指定的文件.你想要在安装 VMware Workstation 前重启 ...

  3. BZOJ_4033_[HAOI2015]树上染色_树形DP

    BZOJ_4033_[HAOI2015]树上染色_树形DP Description 有一棵点数为N的树,树边有边权.给你一个在0~N之内的正整数K,你要在这棵树中选择K个点,将其染成黑色,并 将其他的 ...

  4. vue之axios请求数据本地json

    写给自己的话:静态的json文件要记得放在static文件夹下,想打自己 1.下载插件 npm install axios --save 2.在main.js下引用axios import axios ...

  5. python基础知识-字符串

    字符串: 赋值方法 a = 'name' a = str('name') 字符串的方法: #!/usr/bin/env python class str(object): ""&q ...

  6. GroupItem ContextMenu Command mvvm

    参照:https://stackoverflow.com/questions/38009642/how-do-i-bind-the-menuitem-of-a-contextmenu-of-a-dat ...

  7. day1 java基础回顾-Junit单元测试

    Junit单元测试框架的基本使用 一.搭建环境: 导入junit.jar包(junit4) 二.写测试类: 0,一般一个类对应一个测试类. 1,测试类与被测试类最好是放到同一个包中(可以是不同的源文件 ...

  8. hdu4886 TIANKENG’s restaurant(Ⅱ) (trie树或者模拟进制)

    TIANKENG’s restaurant(Ⅱ) Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 130107/65536 K (Ja ...

  9. JavaEE 企业级分布式高级架构师课程

    总目录: 第一课(2018.7.10) 01 mybatis框架整体概况(2018.7.10)-

  10. CI框架中,判断post,ajax,get请求的方法

    CI框架当中并没有提供,类似tp框架中IS_POST,IS_AJAX,IS_GET的方法. 所有就得我们自己造轮子了.下面就介绍一下,如何定义这些判断请求的方法.其实很简单的. 首先打开constan ...