spring core aop : pointcut example init
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package com.example.aop.member;
|
||||
|
||||
public interface MemberService {
|
||||
|
||||
String hello(String param);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.example.aop.member;
|
||||
|
||||
import com.example.aop.member.annotation.ClassAop;
|
||||
import com.example.aop.member.annotation.MethodAop;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@ClassAop
|
||||
@Component
|
||||
public class MemberServiceImpl implements MemberService {
|
||||
@Override
|
||||
@MethodAop("test value")
|
||||
public String hello(String param) {
|
||||
return "ok";
|
||||
}
|
||||
|
||||
public String internal(String param) {
|
||||
return "ok";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.example.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 {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.example.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();
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.example.aop.pointcut;
|
||||
|
||||
import com.example.aop.member.MemberServiceImpl;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@Slf4j
|
||||
public class ExecutionTest {
|
||||
|
||||
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
|
||||
Method helloMethod;
|
||||
|
||||
@BeforeEach
|
||||
public void init() throws NoSuchMethodException {
|
||||
helloMethod = MemberServiceImpl.class.getMethod("hello", String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void printMethod() {
|
||||
// public java.lang.String com.example.aop.member.MemberServiceImpl.hello(java.lang.String)
|
||||
log.info("helloMethod={}", helloMethod);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user