AspectJ Weaver๋ฅผ ์ฌ์ฉํ XML ๊ธฐ๋ฐ์ ์คํ๋ง AOP ๊ตฌํ ๋ฐฉ๋ฒ
AOP๋?
- Aspect Oriented Programming : ๊ด์ ์งํฅ ํ๋ก๊ทธ๋๋ฐ
- OOP ์ ๋ถ๋ฆฌ๋ ๊ฐ๋ ์ด ์๋๋ผ, OOP์ ๊ธฐ์ด๋ฅผ ๋๋ ํ๋ก๊ทธ๋๋ฐ ๋ฐฉ์
- ํ๋์ ํ๋ก๊ทธ๋จ์ ๊ด์ (ํน์ ๊ด์ฌ์ฌ)๋ผ๋ ๋ ผ๋ฆฌ์ ์ธ ๋จ์๋ก ๋ถ๋ฆฌํ์ฌ ๊ด๋ฆฌํ๋ ๊ฐ๋
- ๋ก๊น , ๊ฐ์ฌ, ์ ์ธ์ ํธ๋์ ์ , ๋ณด์, ์บ์ฑ ๋ฑ ๋ค์ํ ๊ณณ์์ ์ฌ์ฉ๋๋ค.
AOP ์ฉ์ด
- Joint Point : ๋ชจ๋์ด ์ฝ์ ๋์ด ๋์ํ๊ฒ ๋๋ ํน์ ์์น(๋ฉ์๋ ํธ์ถ ๋ฑ)
- Point Cut : ๋ค์ํ Joint Point ์ค์ ์ด๋ค ๊ฒ์ ์ฌ์ฉํ ์ง ์ ํ
- Advice : Joint Point์ ์ฝ์ ๋์ด ๋์ํ ์ ์๋ ์ฝ๋
- Weaving : Advice๋ฅผ ํต์ฌ ๋ก์ง ์ฝ๋์ ์ ์ฉํ๋ ๊ฒ
- Aspect : Point Cut + Advice
Spring AOP Advice ์ข ๋ฅ
- before : ๋ฉ์๋ ํธ์ถ ์ ์ ๋์ํ๋ Advice
- after-returning : ์์ธ ์์ด ํธ์ถ๋ ๋ฉ์๋์ ๋์์ด ์๋ฃ๋๋ฉด ๋์ํ๋ Advice
- after-throwing : ํธ์ถ๋ ๋ฉ์๋ ๋์ ์ค ์์ธ๊ฐ ๋ฐ์ํ์ ๋ ๋์ํ๋ Advice
- after : ์์ธ ๋ฐ์ ์ฌ๋ถ์ ๊ด๊ณ์์ด ํธ์ถ๋ ๋ฉ์๋์ ๋์์ด ์๋ฃ๋๋ฉด ๋์ํ๋ Advice
- around : ๋ฉ์๋ ํธ์ถ ์ ๊ณผ ํ์ ๋์ํ๋ Advice
Spring AOP ๊ตฌํ
AspectJ Weaver๋ฅผ ์ฌ์ฉํ Spring AOP ๊ตฌํ ๋ฐฉ๋ฒ์ XML์ ์ด์ฉํ๋ ๊ฒ๊ณผ @AspectJ ์ ๋ ธํ ์ด์ ์ ์ด์ฉํ๋ ๊ฒ์ผ๋ก ๋๋๋ค.
๋ณธ ๊ธ์์๋ XML ๊ธฐ๋ฐ์ ๊ตฌํ ๋ฐฉ๋ฒ์ ์ดํด๋ณธ๋ค.
๊ด๋ จ ๊ธ - AspectJ Weaver๋ฅผ ์ฌ์ฉํ ์ ๋ ธํ ์ด์ ๊ธฐ๋ฐ์ ์คํ๋ง AOP ๊ตฌํ ๋ฐฉ๋ฒ
1) ๊ณตํต ์ฌํญ
โ AspectJ Weaver ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ถ๊ฐ
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.9.5</version>
</dependency>
โก ๊ด์ฌ์ฌ๋ก ์ค์ ํ ์ฝ๋ ์์ฑ
public class TestBean {
public int method1() {
System.out.println("method1 ํธ์ถ");
return 100;
}
}
๊ด์ฌ์ฌ๋ก ์ค์ ํ ์ฝ๋๋ฅผ ์์ฑํ๋ค.
TestBean ํด๋์ค์ method1() ๋ฉ์๋ ํธ์ถ์ ๊ด์ฌ์ฌ๋ก ์ค์ ํ ๊ฒ์ด๋ค.
๋ค์ํ ์ผ์ด์ค๋ฅผ ํ ์คํธํ๊ธฐ ์ํด intํ ๋ฐ์ดํฐ๋ฅผ ๋ฆฌํดํ๋๋ก ํ์๋ค.
public class MainClass {
public static void main(String[] args) {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");
TestBean bean1 = ctx.getBean("testBean", TestBean.class);
int a1 = bean1.method1();
System.out.printf("a1 : %d\n", a1);
ctx.close();
}
}
main ๋ฉ์๋์์ ApplicationContext ๊ฐ์ฒด๋ฅผ ์์ฑํ๊ณ TestBean ๋น ๊ฐ์ฒด๋ฅผ ๊ฐ์ ธ์จ ๋ค TestBean ํด๋์ค์ method1() ๋ฉ์๋๋ฅผ ํธ์ถํ๋ค.
๐ฅ ์คํ ๊ฒฐ๊ณผ
method1 ํธ์ถ
a1 : 100
Spring AOP๋ฅผ ์ฌ์ฉํด method1()์ ํธ์ถ์ ๊ด์ฌ์ฌ๋ก ์ค์ ํ์ฌ method1() ํธ์ถ ์ , ํ์ ํน์ ๋ฉ์๋๋ฅผ ํธ์ถํ ์ ์๋๋ก ๊ตฌํํ ๊ฒ์ด๋ค.
โข Advisor ํด๋์ค ์์ฑ
public class AdvisorClass {
}
Advice๋ค์ ๋ชจ์๋์ ๊ฒ์ Advisor๋ผ๊ณ ํ๋ค.
์ด ํด๋์ค์ method1()์ ํธ์ถ ์ , ํ์ ํธ์ถํ ๋ฉ์๋๋ฅผ ๊ตฌํํ ๊ฒ์ด๋ค.
2) 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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- ๋น ๋ฑ๋ก -->
<bean id='testBean' class='com.atoz_develop.beans.TestBean'/>
<bean id='advisorClass' class='com.atoz_develop.advisor.AdvisorClass'/>
<!-- AOP ์ค์ -->
<aop:config>
<aop:aspect ref='advisorClass'>
<aop:pointcut id="point1" expression="execution(* method1())"/>
</aop:aspect>
</aop:config>
</beans>
์คํ๋ง xml ์ค์ ์ aop ๋ค์์คํ์ด์ค๋ฅผ ์ถ๊ฐํ๊ณ TestBean, AdvisorClass ํด๋์ค๋ฅผ ๋น์ผ๋ก ๋ฑ๋กํ๋ค.
<aop:config>๋ก AOP ์ค์ ์ ํ๋ค.
<aop:aspect>์ ref ์์ฑ์ advisor ํด๋์ค์ ๋น id๋ฅผ ์ง์ ํ๋ค.
<aop:pointcut>์ expression์ execution ๋ช ์์๋ฅผ ์ฌ์ฉํด์ ํน์ ๊ด์ฌ์ฌ๋ฅผ ์ง์ ํ๋ค.
execution(* method1())๊ณผ ๊ฐ์ด ์ค์ ํ๋ฉด ๋ชจ๋ ํจํค์ง, ๋ชจ๋ ํด๋์ค์ method1() ๋ฉ์๋ ํธ์ถ์ด ๊ด์ฌ์ฌ๊ฐ ๋๋ค.
๐ ์ฐธ๊ณ - [AspectJ Weaver] execution ์ง์์ ์ค์ ๋ฐฉ๋ฒ ์ ๋ฆฌ
โ Before - ๋ฉ์๋ ํธ์ถ ์ ์ ๋์
public class AdvisorClass {
// before advice
public void beforeMethod() {
System.out.println("beforeMethod ํธ์ถ");
}
}
advisor ํด๋์ค์ ๋ฉ์๋ ํธ์ถ ์ ์ ํธ์ถํ ๋ฉ์๋๋ฅผ ๊ตฌํํ๋ค.
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- ๋น ๋ฑ๋ก -->
<bean id='testBean' class='com.atoz_develop.beans.TestBean'/>
<bean id='advisorClass' class='com.atoz_develop.advisor.AdvisorClass'/>
<!-- AOP ์ค์ -->
<aop:config>
<aop:aspect ref='advisorClass'>
<aop:pointcut id="point1" expression="execution(* method1())"/>
<!-- before -->
<aop:before method="beforeMethod" pointcut-ref="point1"/>
</aop:aspect>
</aop:config>
</beans>
<aop:before>๋ก before advice๋ฅผ ์ค์ ํ๋ค.
method์ advisor ํด๋์ค์ ๊ตฌํํ ๋ฉ์๋์ ์ด๋ฆ์, pointcut-ref์ ์์์ ์ค์ ํ <aop:pointcut>์ id๋ฅผ ์ง์ ํ๋ค.
์ด์ method1() ํธ์ถ์ ๋ํ ๊ด์ฌ์ฌ ์ค์ , before advice ๊ตฌํ ๋ฐ ์ค์ ์ด ์๋ฃ๋์๋ค.
๐ฅ ์คํ ๊ฒฐ๊ณผ
beforeMethod ํธ์ถ
method1 ํธ์ถ
a1 : 100
โก After Advice - ์์ธ ๋ฐ์ ์ฌ๋ถ์ ๊ด๊ณ์์ด ํธ์ถ๋ ๋ฉ์๋์ ๋์์ด ์๋ฃ๋๋ฉด ๋์
public class AdvisorClass {
// before advice
public void beforeMethod() {
System.out.println("beforeMethod ํธ์ถ");
}
// after advice
public void afterMethod() {
System.out.println("afterMethod ํธ์ถ");
}
}
advisor ํด๋์ค์ after advice ๋ฉ์๋๋ฅผ ๊ตฌํํ๋ค.
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- ๋น ๋ฑ๋ก -->
<bean id='testBean' class='com.atoz_develop.beans.TestBean'/>
<bean id='advisorClass' class='com.atoz_develop.advisor.AdvisorClass'/>
<!-- AOP ์ค์ -->
<aop:config>
<aop:aspect ref='advisorClass'>
<aop:pointcut id="point1" expression="execution(* method1())"/>
<!-- before -->
<aop:before method="beforeMethod" pointcut-ref="point1"/>
<!-- after -->
<aop:after method="afterMethod" pointcut-ref="point1"/>
</aop:aspect>
</aop:config>
</beans>
<aop:after>๋ก after advice๋ฅผ ์ค์ ํ๋ค.
์ค์ ๋ฐฉ๋ฒ์ <aop:before>์ ๋์ผํ๋ค.
๐ฅ ์คํ ๊ฒฐ๊ณผ
beforeMethod ํธ์ถ
method1 ํธ์ถ
afterMethod ํธ์ถ
a1 : 100
โข Around Advice - ๋ฉ์๋ ํธ์ถ ์ ๊ณผ ํ์ ๋์
import org.aspectj.lang.ProceedingJoinPoint;
public class AdvisorClass {
// before advice
public void beforeMethod() {
System.out.println("beforeMethod ํธ์ถ");
}
// after advice
public void afterMethod() {
System.out.println("afterMethod ํธ์ถ");
}
// around advice
public Object aroundMethod(ProceedingJoinPoint pjp) throws Throwable{
System.out.println("aroundMethod ํธ์ถ1");
// ์๋์ ๋ฉ์๋๋ฅผ ํธ์ถํ๋ค.
Object obj = pjp.proceed();
System.out.println("aroundMethod ํธ์ถ 2");
return obj;
}
}
advisor ํด๋์ค์ around adivce ๋ฉ์๋๋ฅผ ๊ตฌํํ๋ค.
์ด ๋๋ org.aspectj.lang.ProceedingJoinPoint๋ฅผ ๋ฉ์๋์ ์ธ์๋ก ๋ฐ์์ ์ด ๊ฐ์ฒด์ proceed()๋ฅผ ํธ์ถํ์ฌ ์์ ์ค๊ฐ์ ์๋ ๋ฉ์๋๋ฅผ ํธ์ถํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํํ๋ค.
์๋ ๋ฉ์๋๊ฐ ๋ฆฌํด๊ฐ์ด ์์ ๊ฒฝ์ฐ Object ํ์ ์ผ๋ก ๋ฐ์์ ๋ฐํํ๋ค.
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- ๋น ๋ฑ๋ก -->
<bean id='testBean' class='com.atoz_develop.beans.TestBean'/>
<bean id='advisorClass' class='com.atoz_develop.advisor.AdvisorClass'/>
<!-- AOP ์ค์ -->
<aop:config>
<aop:aspect ref='advisorClass'>
<aop:pointcut id="point1" expression="execution(* method1())"/>
<!-- before -->
<aop:before method="beforeMethod" pointcut-ref="point1"/>
<!-- after -->
<aop:after method="afterMethod" pointcut-ref="point1"/>
<!-- around -->
<aop:around method="aroundMethod" pointcut-ref="point1"/>
</aop:aspect>
</aop:config>
</beans>
<aop:around>๋ก after advice๋ฅผ ์ค์ ํ๋ค.
๐ฅ ์คํ ๊ฒฐ๊ณผ
beforeMethod ํธ์ถ
aroundMethod ํธ์ถ1
method1 ํธ์ถ
aroundMethod ํธ์ถ 2
afterMethod ํธ์ถ
a1 : 100
โฃ After-Returning Advice - ์์ธ ์์ด ํธ์ถ๋ ๋ฉ์๋์ ๋์์ด ์๋ฃ๋๋ฉด ๋์
import org.aspectj.lang.ProceedingJoinPoint;
public class AdvisorClass {
// before advice
public void beforeMethod() {
System.out.println("beforeMethod ํธ์ถ");
}
// after advice
public void afterMethod() {
System.out.println("afterMethod ํธ์ถ");
}
// around advice
public Object aroundMethod(ProceedingJoinPoint pjp) throws Throwable{
System.out.println("aroundMethod ํธ์ถ1");
// ์๋์ ๋ฉ์๋๋ฅผ ํธ์ถํ๋ค.
Object obj = pjp.proceed();
System.out.println("aroundMethod ํธ์ถ 2");
return obj;
}
// after-returning advice
public void afterReturningMethod() {
System.out.println("afterReturningMethod ํธ์ถ");
}
}
After advice ๋ฉ์๋ ๊ตฌํ ๋ฐฉ๋ฒ์ before, after์ ๋ค๋ฅด์ง ์๋ค.
๋งค๊ฐ๋ณ์ ์์ด ์ํํ ์์ ์ ๊ตฌํํ๋ฉด ๋๋ค.
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- ๋น ๋ฑ๋ก -->
<bean id='testBean' class='com.atoz_develop.beans.TestBean'/>
<bean id='advisorClass' class='com.atoz_develop.advisor.AdvisorClass'/>
<!-- AOP ์ค์ -->
<aop:config>
<aop:aspect ref='advisorClass'>
<aop:pointcut id="point1" expression="execution(* method1())"/>
<!-- before -->
<aop:before method="beforeMethod" pointcut-ref="point1"/>
<!-- after -->
<aop:after method="afterMethod" pointcut-ref="point1"/>
<!-- around -->
<aop:around method="aroundMethod" pointcut-ref="point1"/>
<!-- after-returning -->
<aop:after-returning method="afterReturningMethod" pointcut-ref="point1"/>
</aop:aspect>
</aop:config>
</beans>
<aop:after-returning>์ผ๋ก ์ค์ ํ๋ค.
๐ฅ ์คํ ๊ฒฐ๊ณผ
beforeMethod ํธ์ถ
aroundMethod ํธ์ถ1
method1 ํธ์ถ
afterReturningMethod ํธ์ถ
aroundMethod ํธ์ถ 2
afterMethod ํธ์ถ
a1 : 100
โค After-Throwing Advice - ํธ์ถ๋ ๋ฉ์๋ ๋์ ์ค ์์ธ๊ฐ ๋ฐ์ํ์ ๋ ๋์
import org.aspectj.lang.ProceedingJoinPoint;
public class AdvisorClass {
// before advice
public void beforeMethod() {
System.out.println("beforeMethod ํธ์ถ");
}
// after advice
public void afterMethod() {
System.out.println("afterMethod ํธ์ถ");
}
// around advice
public Object aroundMethod(ProceedingJoinPoint pjp) throws Throwable{
System.out.println("aroundMethod ํธ์ถ1");
// ์๋์ ๋ฉ์๋๋ฅผ ํธ์ถํ๋ค.
Object obj = pjp.proceed();
System.out.println("aroundMethod ํธ์ถ 2");
return obj;
}
// after-returning advice
public void afterReturningMethod() {
System.out.println("afterReturningMethod ํธ์ถ");
}
// after-throwing advice
public void afterThrowingMethod(Throwable e1) {
System.out.println("afterThrowingMethod ํธ์ถ");
System.out.println(e1);
}
}
After-throwing advice ๋ฉ์๋๋ ๋ฐ์ํ ์์ธ๋ฅผ ๋ฉ์๋ ์๊ท๋จผํธ๋ก ๋ฐ์ ์์ธ ์ ๋ณด๋ฅผ ์ถ๋ ฅํ๋ ๋ฑ์ ์ถ๊ฐ ์์ ์ ํ ์ ์๋ค.
<?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:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- ๋น ๋ฑ๋ก -->
<bean id='testBean' class='com.atoz_develop.beans.TestBean'/>
<bean id='advisorClass' class='com.atoz_develop.advisor.AdvisorClass'/>
<!-- AOP ์ค์ -->
<aop:config>
<aop:aspect ref='advisorClass'>
<aop:pointcut id="point1" expression="execution(* method1())"/>
<!-- before -->
<aop:before method="beforeMethod" pointcut-ref="point1"/>
<!-- after -->
<aop:after method="afterMethod" pointcut-ref="point1"/>
<!-- around -->
<aop:around method="aroundMethod" pointcut-ref="point1"/>
<!-- after-returning -->
<aop:after-returning method="afterReturningMethod" pointcut-ref="point1"/>
<!-- after-throwing -->
<aop:after-throwing method="afterThrowingMethod" pointcut-ref="point1" throwing="e1"/>
</aop:aspect>
</aop:config>
</beans>
after-throwing advice๋ <aop:after-throwing>์ผ๋ก ์ค์ ํ๋๋ฐ, ์์ธ ๊ฐ์ฒด๋ฅผ after-throwing advice ๋ฉ์๋์์ ๋ฐ์ ์ ์๋๋ก throwing ์์ฑ์ ์ฌ์ฉํด์ ๋ฉ์๋์ ์์ธ ์๊ท๋จผํธ ์ด๋ฆ์ ์ง์ ํ๋ค.
public class TestBean {
public int method1() {
System.out.println("method1 ํธ์ถ");
int a1 = 10 / 0; // ์์ธ ๋ฐ์
return 100;
}
}
ํ ์คํธ๋ฅผ ์ํด method1()์์ ์์ธ๋ฅผ ๋ฐ์์ํค๋ ์ฝ๋๋ฅผ ์ถ๊ฐํ๋ค.
๐ฅ ์คํ ๊ฒฐ๊ณผ
beforeMethod ํธ์ถ
aroundMethod ํธ์ถ1
method1 ํธ์ถ
afterThrowingMethod ํธ์ถ
java.lang.ArithmeticException: / by zero
afterMethod ํธ์ถ
Exception in thread "main" java.lang.ArithmeticException: / by zero
at com.atoz_develop.beans.TestBean.method1(TestBean.java:8)
at com.atoz_develop.beans.TestBean$$FastClassBySpringCGLIB$$13abe977.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:749)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:62)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.adapter.AfterReturningAdviceInterceptor.invoke(AfterReturningAdviceInterceptor.java:55)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:88)
at com.atoz_develop.advisor.AdvisorClass.aroundMethod(AdvisorClass.java:22)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.aspectj.AspectJAfterAdvice.invoke(AspectJAfterAdvice.java:47)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:56)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
at com.atoz_develop.beans.TestBean$$EnhancerBySpringCGLIB$$b59cccdc.method1(<generated>)
at com.atoz_develop.main.MainClass.main(MainClass.java:15)
Process finished with exit code 1
๊ด์ฌ์ฌ๋ก ์ค์ ํ method1() ํธ์ถ ์ค ์์ธ๊ฐ ๋ฐ์ํ์ after-returning advice ๋ฉ์๋ ๋์ after-throwing advice ๋ฉ์๋๊ฐ ํธ์ถ๋๋ ๊ฒ์ ๋ณผ ์ ์๋ค.
ํ
์คํธ ํ method1()์์ ์์ธ๋ฅผ ๋ฐ์์ํค๊ธฐ ์ํด ์ถ๊ฐํ ์ฝ๋๋ฅผ ์ญ์ ํ๋ ๊ฒ์ ์์ง ๋ง์.
๊ด๋ จ ๊ธ
- AspectJ Weaver๋ฅผ ์ฌ์ฉํ ์ ๋ ธํ ์ด์ ๊ธฐ๋ฐ์ ์คํ๋ง AOP ๊ตฌํ ๋ฐฉ๋ฒ
- [AspectJ Weaver] execution ์ง์์ ์ค์ ๋ฐฉ๋ฒ ์ ๋ฆฌ
๋๊ธ