- 浏览: 56959 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (93)
- java (3)
- ios (9)
- wp (15)
- android (0)
- js (1)
- 服务器 (0)
- db (0)
- linux (1)
- python (0)
- xcode (0)
- ide (2)
- maven (0)
- spring (0)
- sql (0)
- 第三方 (1)
- nexus (0)
- nginx (11)
- tomcat (0)
- jenkins (0)
- zookeeper (1)
- git (1)
- svn (0)
- uml (0)
- redis (4)
- activemq (1)
- flume (0)
- kafka (0)
- mysql (1)
- memcached (0)
- mybatis (0)
- mac (0)
- mongo (1)
- docker (6)
- cache (0)
- jvm (0)
- markdown (0)
- springboot (24)
- mycat (3)
- LTS (3)
- 运维 (0)
- opts (1)
- netty (1)
- tcc (0)
- ffmpeg (2)
- 直播 (6)
- cxf (0)
- nodejs (0)
- storm (0)
- elasticjob (0)
- php (0)
最新评论
===================================================
application.properties 增加aop选项
===================================================
# AOP
spring.aop.auto=true
spring.aop.proxy-target-class=true
如果proxy-target-class 属性值被设置为true,那么基于类的代理将起作用(这时需要cglib库)。
如果proxy-target-class属值被设置为false或者这个属性被省略,那么标准的JDK 基于接口的代理。
如果不给出 proxy-target-class,就按 proxy-target-class=“false”对待,也即是按JDK proxy来处理的。
===================================================
AopTest.java
<bean id="logService" class="org.spring.springboot.aop.AopTest"/>
<aop:config>
<aop:aspect id="log" ref="logService">
<aop:pointcut expression="execution(public * org.spring.springboot.web..*.*(..))" id="cLog"/>
<aop:before method="around" pointcut-ref="cLog"/>
<aop:before method="before" pointcut-ref="cLog"/>
<aop:after method="after" pointcut-ref="cLog"/>
<aop:after-returning method="doAfterReturning" pointcut-ref="cLog" returning="object"/>
<aop:after-throwing method="doAfterThrowing" pointcut-ref="cLog" arg-names="joinpoint,exception"
throwing="exception"/>
</aop:aspect>
</aop:config>
===================================================
@Aspect
@Component
public class AopTest {
@Pointcut("execution(public * org.spring.springboot.web..*.*(..))")
public void webLog(){}
@Before("webLog()")
public void before(JoinPoint joinpoint) {
// 此方法返回的是一个数组,数组中包括request以及ActionCofig等类对象
Object[] args = joinpoint.getArgs();
if (args != null && args.length > 0) {
if (args[0] instanceof HttpServletRequest) {
HttpServletRequest request = (HttpServletRequest) args[0];
System.out.println("Request URI: " + request.getRequestURI());
}
}
}
@After("webLog()")
public void after(JoinPoint joinpoint) {
System.out.println("joinpoint = [" + joinpoint + "]");
}
@AfterReturning(returning = "ret", pointcut = "webLog()")
public void doAfterReturning(Object ret) throws Throwable {
System.out.println("ret = [" + ret + "]");
}
@AfterThrowing(pointcut = "webLog()", argNames = "joinpoint,exception", throwing = "exception")
public void doAfterThrowing(JoinPoint joinpoint, Exception exception) {
String className = joinpoint.getTarget().getClass().getName();// 类名
String methodName = joinpoint.getSignature().getName();// 方法名字
String content = "--------------------------------reqlog. Exception error class "
+ className
+ "_"
+ methodName
+ "====== message ======"
+ exception.getMessage();
System.out.println(content);
System.out.println(exception);
}
}
application.properties 增加aop选项
===================================================
# AOP
spring.aop.auto=true
spring.aop.proxy-target-class=true
如果proxy-target-class 属性值被设置为true,那么基于类的代理将起作用(这时需要cglib库)。
如果proxy-target-class属值被设置为false或者这个属性被省略,那么标准的JDK 基于接口的代理。
如果不给出 proxy-target-class,就按 proxy-target-class=“false”对待,也即是按JDK proxy来处理的。
===================================================
AopTest.java
<bean id="logService" class="org.spring.springboot.aop.AopTest"/>
<aop:config>
<aop:aspect id="log" ref="logService">
<aop:pointcut expression="execution(public * org.spring.springboot.web..*.*(..))" id="cLog"/>
<aop:before method="around" pointcut-ref="cLog"/>
<aop:before method="before" pointcut-ref="cLog"/>
<aop:after method="after" pointcut-ref="cLog"/>
<aop:after-returning method="doAfterReturning" pointcut-ref="cLog" returning="object"/>
<aop:after-throwing method="doAfterThrowing" pointcut-ref="cLog" arg-names="joinpoint,exception"
throwing="exception"/>
</aop:aspect>
</aop:config>
===================================================
@Aspect
@Component
public class AopTest {
@Pointcut("execution(public * org.spring.springboot.web..*.*(..))")
public void webLog(){}
@Before("webLog()")
public void before(JoinPoint joinpoint) {
// 此方法返回的是一个数组,数组中包括request以及ActionCofig等类对象
Object[] args = joinpoint.getArgs();
if (args != null && args.length > 0) {
if (args[0] instanceof HttpServletRequest) {
HttpServletRequest request = (HttpServletRequest) args[0];
System.out.println("Request URI: " + request.getRequestURI());
}
}
}
@After("webLog()")
public void after(JoinPoint joinpoint) {
System.out.println("joinpoint = [" + joinpoint + "]");
}
@AfterReturning(returning = "ret", pointcut = "webLog()")
public void doAfterReturning(Object ret) throws Throwable {
System.out.println("ret = [" + ret + "]");
}
@AfterThrowing(pointcut = "webLog()", argNames = "joinpoint,exception", throwing = "exception")
public void doAfterThrowing(JoinPoint joinpoint, Exception exception) {
String className = joinpoint.getTarget().getClass().getName();// 类名
String methodName = joinpoint.getSignature().getName();// 方法名字
String content = "--------------------------------reqlog. Exception error class "
+ className
+ "_"
+ methodName
+ "====== message ======"
+ exception.getMessage();
System.out.println(content);
System.out.println(exception);
}
}
发表评论
-
springboot:condition
2017-07-26 11:10 335public class LinuxCondition imp ... -
springboot:tomcat启动
2017-07-20 15:02 8901.在pom.xml里设置 <packaging> ... -
springboot:shiro
2017-07-13 15:52 925第一次学习系统学习shiro 并将shiro集成到sprin ... -
springboot:upload
2017-07-06 10:25 719FileUploadConfiguration.java == ... -
springboot:servlet
2017-07-06 10:17 469Application.java ============== ... -
springboot:freemarker
2017-07-05 17:33 482pom.xml ======================= ... -
springboot:task
2017-07-05 12:11 405TaskPool.java ================= ... -
springboot:热部署
2017-07-05 11:23 323pom.xml: ====================== ... -
springboot:注解
2017-07-04 11:36 577@EnableAutoConfiguration注解 excl ... -
springboot:server属性配置
2017-07-04 10:05 683server配置 ====================== ... -
springboot:memcached
2017-07-03 17:23 871pom.xml ======================= ... -
springboot:health
2017-07-03 16:43 363<dependency> ... -
springboot:mongodb
2017-07-03 15:38 1531pom.xml ======================= ... -
springboot:quartz集群
2017-07-02 20:40 971pom.xml ======================= ... -
springboot:ControllerAdvice
2017-07-02 14:09 350全局异常拦截 //@ControllerAdvice(anno ... -
springboot:dubbo
2017-07-02 10:40 473server: ======================= ... -
springboot:amq
2017-07-01 22:20 437pom.xml ======================= ... -
springboot:redis(jedis)
2017-07-01 14:10 879application.properties ======== ... -
springboot:mybatis&druid&pagehelper
2017-07-01 13:35 376=============================== ... -
springboot:logback
2017-06-30 16:20 495=============================== ...
相关推荐
Springboot整合AOP AOP概念:面向切面编程:扩展功能不修改源代码实现 AOP采用横向抽取机制,取代传统的纵向继承体系重复性代码(性能监视,事务管理,安全检查,缓存)
SpringBoot+AOP+TraceID.pdf
通过SpringAop实现多数据源的动态切换 并采用Druid连接池,可扩展继续增加数据库配置。
springboot 用aop打印web请求参数信息例子;springboot 用aop打印web请求参数信息例子;springboot 用aop打印web请求参数信息例子
springboot spring aop 拦截器 注解方式实现脱敏(涉及到:pom.xml -->application.properties --->启动类-->拦截器)
只是简单集成了下一个aop的前置before小demo,自己做记录.
SpringBoot 整合 AOP【完整源码】
该项目运用SpringBoot框架,MyBatis持久层,SqlSession映射,AOP技术,对项目日志进行管理
aop_demo.zip
内容概要:springboot+拦截器+aop+自定义注解+本地线程实现统一接口日志记录,记录下接口所在模块、接口描述、接口请求参数、接口返回参数、接口请求时间以及接口耗时用于接口优化,接口记录参数以及操作人防止使用...
SpringBoot使用AOP完成多数据源切换,下载后导入即可使用,JDK1.8
SpringBoot AOP 写法一: @Before("execution(* com.bjpowernode.springboot07.javabean.Man.eat(..))") 一、AOP开发 1.1 概述 1.2使用方法 1.3创建项目并添加maven依赖 1.4 创建Javabean测试类 1.5 创建切面 1.6 ...
springBoot+mybatis+AOP实现读写分离,在代码层面直接实现,无需任何插件,简单易懂,非常适合作为解决数据库并发大的解决方案
1.使用aop切面编程解耦 2.使用spring事件监听保存日志 3.日志内容详细包括请求ip、请求响应数据、异常信息等
SpringBoot之AOP面向切面编程实例
【Spring】Spring中AOP的简介和基本使用,SpringBoot使用AOP
SpringBoot AOP各种注解、自定义注解、鉴权使用案例SpringBoot AOP各种注解、自定义注解、鉴权使用案例SpringBoot AOP各种注解、自定义注解、鉴权使用案例
高级软件人才培训专家_day13-SpringBootWeb AOP
涵盖SpringBoot的AOP、Slf4j日志门面-springboot-in-action
主要介绍了解决springboot的aop切面不起作用问题(失效的排查),具有很好的参考价值,希望对大家有所帮助。 一起跟随小编过来看看吧