-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
섹션11: 스프링 AOP - 포인트컷
- Loading branch information
Showing
5 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
스프링 로드맵5 고급편/aop/src/main/java/hello/aop/member/MemberService.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package hello.aop.member; | ||
|
||
public interface MemberService { | ||
String hello(String param); | ||
} |
19 changes: 19 additions & 0 deletions
19
스프링 로드맵5 고급편/aop/src/main/java/hello/aop/member/MemberServiceImpl.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package hello.aop.member; | ||
|
||
import hello.aop.member.annotation.ClassAop; | ||
import hello.aop.member.annotation.MethodAop; | ||
import org.springframework.stereotype.Component; | ||
|
||
@ClassAop | ||
@Component | ||
public class MemberServiceImpl implements MemberService { | ||
@Override | ||
@MethodAop("test value") | ||
public String hello(final String param) { | ||
return "ok"; | ||
} | ||
|
||
public String internal(String param) { | ||
return "ok"; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
스프링 로드맵5 고급편/aop/src/main/java/hello/aop/member/annotation/ClassAop.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package hello.aop.member.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.TYPE) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ClassAop { | ||
} |
12 changes: 12 additions & 0 deletions
12
스프링 로드맵5 고급편/aop/src/main/java/hello/aop/member/annotation/MethodAop.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package hello.aop.member.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.METHOD) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface MethodAop { | ||
String value(); | ||
} |
30 changes: 30 additions & 0 deletions
30
스프링 로드맵5 고급편/aop/src/test/java/hello/aop/pointcut/ExecutionTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package hello.aop.pointcut; | ||
|
||
import hello.aop.member.MemberServiceImpl; | ||
import java.lang.reflect.Method; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.aop.aspectj.AspectJExpressionPointcut; | ||
|
||
@Slf4j | ||
public class ExecutionTest { | ||
|
||
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); | ||
Method helloMethod; | ||
|
||
@BeforeEach | ||
public void init() throws NoSuchMethodException { | ||
// 테스트에서 실행할 수 있게 getMethod()를 추출해서 helloMethod에 보관 | ||
helloMethod = MemberServiceImpl.class.getMethod("hello", String.class); | ||
} | ||
|
||
@Test | ||
void printMethod() { | ||
|
||
// 앞으로 알아볼 execution으로 시작하는 포인트컷 표현식은 이 메서드 정보를 매칭해서 포인트컷 대상을 찾아낸다. | ||
// execution(* ..package..Class.) | ||
// public java.lang.String hello.aop.member.MemberServiceImpl.hello(java.lang.String) | ||
log.info("helloMethod={}", helloMethod); | ||
} | ||
} |