applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd">
<aop:aspectj-autoproxy/>
<bean class="com.demo3.MyAspect"/>
<bean id="demoService3" class="com.demo3.core.DemoServiceImpl"/>
</beans>
=========================================================================================================================================================
DemoService.java
package com.demo3.core;
public interface DemoService {
public void save(String value);
public void write();
}
=========================================================================================================================================================
package com.demo3.core;
public class DemoServiceImpl implements DemoService{
private String value;
@Override
public void save(String value) {
// int a=this.value.length(); //예외 발생 (현재 value는 null이기 때문에)
this.value=value;
}
@Override
public void write() {
System.out.println(value);
}
}
ResultMain을 실행시킨 결과
에러 없을 때 순서
@Before : 메소드 --> save
@After : 메소드 -->save
@AfterReturning : 메소드 --> save, retrun : null
@Before : 메소드 --> write
스프
@After : 메소드 -->write
@AfterReturning : 메소드 --> write, retrun : null
에러 발생시 실행 순서
@Before : 메소드 --> save
@After : 메소드 -->save
@AfterThrowing : 메소드 -->save, throws
에러가 나기전까지만 실행하고 AfterThrowing만 실행
'spring > AOP' 카테고리의 다른 글
AOP 구현하는 방법2 : aop namespace를 이용한 방법 (0) | 2014.05.07 |
---|---|
AOP 구현하는 방법1 : Proxy를 통한 간접 접근 (0) | 2014.05.07 |
AOP 용어 (0) | 2014.05.07 |
AOP 구조를 이해하는 예제2(MethodInterceptor) (0) | 2013.08.09 |
AOP 구조를 이해하는 예제1 (0) | 2013.08.09 |