Spring 全注解配置 bean 和 调用 (9) 5种通知

来源:互联网 发布:深入浅出node.js系列 编辑:程序博客网 时间:2024/06/06 11:44
package com.xiuye.config.aspect;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotation.After;import org.aspectj.lang.annotation.AfterReturning;import org.aspectj.lang.annotation.AfterThrowing;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.annotation.Pointcut;/*import org.springframework.context.annotation.Configuration;import org.springframework.stereotype.Component;*/@Aspect//@Configurationpublic class AspectConfig {@Before("execution(** com.xiuye.component.*.description())")public void beforeDescription(){System.out.println("Before method:description!");}@Pointcut("execution(** com.xiuye.component.*.description())")public void description(){}@After("description()")public void afterDescription(){System.out.println("After method:description!");}@AfterReturning("description()")public void afterReturningDescription(){System.out.println("AfterReturning method:description!");}@AfterThrowing("description()")public void afterThrowingDescription(){System.out.println("AfterThrowing method:description!");}@Around("description()")//始终在其通知前面执行public void aroundDescription(ProceedingJoinPoint jp){System.out.println("Around method:description!");System.out.println("Hello World!");try {jp.proceed();} catch (Throwable e) {e.printStackTrace();}System.out.println("Is game over?!");}}

十一月 12, 2016 7:59:21 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getDefaultTestExecutionListenerClassNames信息: Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener]十一月 12, 2016 7:59:21 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper instantiateListeners信息: Could not instantiate TestExecutionListener [org.springframework.test.context.web.ServletTestExecutionListener]. Specify custom listener classes or make the default listener classes (and their required dependencies) available. Offending class: [javax/servlet/ServletContext]十一月 12, 2016 7:59:21 下午 org.springframework.test.context.support.DefaultTestContextBootstrapper getTestExecutionListeners信息: Using TestExecutionListeners: [org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@1be98f5, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@1adae5d, org.springframework.test.context.support.DirtiesContextTestExecutionListener@17f6480, org.springframework.test.context.transaction.TransactionalTestExecutionListener@16e8792, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@12cbfa]十一月 12, 2016 7:59:21 下午 org.springframework.context.support.GenericApplicationContext prepareRefresh信息: Refreshing org.springframework.context.support.GenericApplicationContext@1560810: startup date [Sat Nov 12 19:59:21 CST 2016]; root of context hierarchyActive profile := devtest := trueAround method:description!Hello World!Before method:description!I'm car's steer!Is game over?!After method:description!AfterReturning method:description!Around method:description!Hello World!Before method:description!I'm car's wheels!Is game over?!After method:description!AfterReturning method:description!Around method:description!Hello World!Before method:description!I'm car's engine!Is game over?!After method:description!AfterReturning method:description!十一月 12, 2016 7:59:22 下午 org.springframework.context.support.GenericApplicationContext doClose信息: Closing org.springframework.context.support.GenericApplicationContext@1560810: startup date [Sat Nov 12 19:59:21 CST 2016]; root of context hierarchy

0 0
原创粉丝点击