springboot之AOP配置
来源:互联网 发布:芒果tv mac版下载 编辑:程序博客网 时间:2024/04/30 08:59
package com.didi.controller;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;
@Aspect
@Component
public class SleepHelper {
@Before("sleep()")public void beforeSleep(){ System.out.println("睡前刷牙---------");}@Pointcut("execution(* com.didi.domain.*.*(..))")public void sleep(){};@After("sleep()")public void wakeUp(){ System.out.println("醒来洗漱--------------");}
}
package com.didi.domain;
import org.springframework.stereotype.Component;
@Component
public class Man {
public void study(){ System.out.println("我正在学C++");}
}
package com.didi;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
@Component
public class SpringUtils implements ApplicationContextAware {
private static ApplicationContext applicationContext;@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; System.out.println("容器保存成功-----------");}public static ApplicationContext getApplicationContext(){ return applicationContext;}
}
package com.didi.controller;
import com.didi.SpringUtils;
import com.didi.domain.Man;
import org.hibernate.service.spi.InjectService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
public class AopController {
@RequestMapping("aopMapping")public void aop(){ Man man = (Man)SpringUtils.getApplicationContext().getBean("man"); man.study();}
}
访问:http://localhost:9006/aopMapping
控制台打印:
睡前刷牙———
我正在学C++
醒来洗漱————–
- springboot之AOP配置
- Springboot配置aop
- SpringBoot中AOP的配置
- SpringBoot之集成Spring AOP
- SpringBoot之集成Spring AOP
- SpringBoot之集成Spring AOP
- SpringBoot之集成Spring AOP
- (7)学习SpringBoot 之 AOP
- springboot-AOP
- SpringBoot-AOP
- springBoot aop
- SpringBoot之SSL配置(SpringBoot实战)
- Spring配置之AOP
- Springboot+Mybatis+Pagehelper+Aop动态配置Oracle、Mysql数据源
- SpringBoot配置属性之MVC
- SpringBoot配置属性之Server
- SpringBoot配置属性之DataSource
- SpringBoot配置属性之NOSQL
- 数塔——DP算法
- Android for All 术语表
- javascript
- 《neural network and deep learning》题解——ch02 Network源码分析
- 黑盒测试(功能测试)
- springboot之AOP配置
- Golang教程:(十五)指针
- VMWare启动虚拟机系统时,出现“内部错误”的解决办法
- TensorFlow保存和加载训练模型
- LA-3713-TwoSAT
- 以上为Python3.*及更早之前的方式,最新Pyhon3.*的调用方式: def md5Encode(str): import hashlib #参数必须是byte
- [Python] python-ldap installation and usage notes
- 【二叉树】指定深度添加一层节点【623. Add One Row to Tree】
- BSS 未初始化段