Created
April 9, 2019 19:56
-
-
Save benelog/0434aae381b95d66d70bfab9942f9fd5 to your computer and use it in GitHub Desktop.
spring aop order 테스트
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.test.aop; | |
import org.aspectj.lang.JoinPoint; | |
import org.aspectj.lang.annotation.Aspect; | |
import org.aspectj.lang.annotation.Before; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.aop.support.AopUtils; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.context.annotation.EnableAspectJAutoProxy; | |
import org.springframework.core.annotation.Order; | |
import org.springframework.stereotype.Component; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringRunner; | |
import org.springframework.test.context.support.AnnotationConfigContextLoader; | |
@RunWith(SpringRunner.class) | |
@ContextConfiguration(loader= AnnotationConfigContextLoader.class) | |
public class AspectTest { | |
@Autowired Runnable main; | |
@Test | |
public void checkOrder() throws Exception { | |
System.out.println(AopUtils.isAopProxy(main)); | |
main.run(); | |
} | |
@Configuration | |
@EnableAspectJAutoProxy | |
static public class TestContext { | |
@Bean | |
public Runnable main() { | |
return new Runnable() { | |
public void run() { | |
System.out.println("target executed"); | |
} | |
}; | |
} | |
@Aspect | |
@Order(-1) | |
@Component | |
public static class OrderMinus1Aspect { | |
@Before("execution(void *.run())") | |
public void printOrder(JoinPoint jp) { | |
System.out.println("order -1"); | |
} | |
} | |
@Aspect | |
@Order(0) | |
@Component | |
public static class Order0Aspect { | |
@Before("execution(void *.run())") | |
public void printOrder(JoinPoint jp) { | |
System.out.println("order 0"); | |
} | |
} | |
@Aspect | |
@Order(1) | |
@Component | |
public static class Order1Aspect { | |
@Before("execution(void *.run())") | |
public void printOrder(JoinPoint jp) { | |
System.out.println("order 1"); | |
} | |
} | |
@Aspect | |
@Order(2) | |
@Component | |
public static class Order2Aspect { | |
@Before("execution(void *.run())") | |
public void printOrder(JoinPoint jp) { | |
System.out.println("order 2"); | |
} | |
} | |
} | |
} | |
Author
benelog
commented
Apr 23, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment