ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码

Spring中AOP实例详解(2/2)

来源:网络整理     时间:2015-12-05     关键词:Spring,Annotation,Application

本篇文章主要介绍了"Spring中AOP实例详解",主要涉及到Spring,Annotation,Application方面的内容,对于Javajrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下: Spring中AOP实例详解 需要增强的服务假如有以下service,他的功能很简单,打印输入的参数并返回参数。@Servicepublic class Sim...

Around增强--around start...
修改传入参数后执行输出:
get name is: around_add_Bob
Around增强--around end

After增强

    // 无论是否发生异常都会 处理
    @After(pointCut())
    public void after() {
        System.out.println(After增强--always do no matter what happen);
    }

输出:

get name is: Bob
After增强--always do no matter what happen  

AfterThrowing增强

    @AfterThrowing(pointcut = pointCut(), throwing = ex)
    public void afterThrowing(JoinPoint jp, Throwable ex) {
        System.out.println(error is:  + ex);
    }

这里没抛异常,就没有输出了

测试代码如下

@Configuration
@EnableAspectJAutoProxy
@ComponentScan(basePackages = com.ydoing.service,com.ydoing.aspect)
public class AppConfig {
    public static void main(String[] args) {
        @SuppressWarnings(resource)
        ApplicationContext ctx = new AnnotationConfigApplicationContext(AppConfig.class);
        SimpleService service = ctx.getBean(SimpleService.class);
        service.getName(Bob);
    }
}

 

原文地址:http://www.bkjia.com/Javabc/1077751.html

 QQ群290551701 聚集很多互联网精英,技术总监,架构师,项目经理!开源技术研究,欢迎业内人士,大牛及新手有志于从事IT行业人员进入!

以上就介绍了Spring中AOP实例详解,包括了Spring,Annotation,Application方面的内容,希望对Javajrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_237828_2.html

相关图片

相关文章