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
相关文章推荐
- Spring 全注解配置 bean 和 调用 (7) properties文件注入
- servlet调用spring容器中的bean,的两种方式一种注解一种xml配置
- Spring的XML配置的bean调用注解方式的bean
- Spring 全注解配置 bean 和 调用 (8) @Aspect注解不生效解决办法 和 no-static 的警告解决办法
- Spring 全注解配置 bean 和 调用 (2) @Profile 自适应不同的模式或环境中
- Spring 全注解配置 bean 和 调用 (1)
- Spring 全注解配置 bean 和 调用 (5) @Qualifier 自动装配歧义性消除
- servlet调用spring容器中的bean,的两种方式一种注解一种xml配置
- Spring 全注解配置 bean 和 调用 (3) @Conditonal 条件化的配置bean
- Spring 全注解配置 bean 和 调用 (6) 自定义注解 自动装配歧义性消除
- Spring 全注解配置 bean 和 调用 (4) @Primary 自动装配歧义性
- Spring--通过注解来配置bean
- spring注解时AOP失效,XML配置<bean>正常
- servlet调用spring中的bean(注解方式)
- spring 注解方式配置Bean
- spring 调用 bean (xml 和 注解) sessionFactory no this bean
- 【第十二章】零配置 之 12.3 注解实现Bean定义、12.4基于Java类定义Bean配置元数据 ——跟我学spring3
- 零配置 之 12.3 注解实现Bean定义 ——跟我学spring3
- JSP页面怎样调用Spring配置文件中定义的Bean
- [java][spring]取得通过配置文件和注解注入的bean、取得当前数据库连接、取得ApplicationContext的方法