您的位置:首页 > 编程语言 > Java开发

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

2016-11-12 20:02 357 查看
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
//@Configuration
public 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 hierarchy
Active profile := dev
test := true
Around 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: