hello() 메소드가 이 아니고이 아니라는 사실을 알기 원하면 @RequestMapping 메소드 호출에서 AOP를 수행하려고합니다.스프링 부트의 개인/보호 된 RequestMapping에서 AOP를 수행하는 방법
@RestController
class HelloController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
String hello() {
return "Hello";
}
}
여기에 내가 @Aspect, @EnableAspectJAutoProxy 주석을 추가 한 기본 클래스입니다. 난 그냥 의존성 아래에 추가의 pom.xml에
@Aspect
@EnableAspectJAutoProxy(proxyTargetClass = true)
@SpringBootApplication
public class FooServiceApplication {
public static void main(String[] args) {
SpringApplication.run(FooServiceApplication.class, args);
}
@Around("@annotation(requestMapping)")
public Object around(ProceedingJoinPoint pjp, RequestMapping requestMapping) throws Throwable {
return pjp.proceed();
}
}
는 :
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
결과는 예와 같은 경우 같은 방법이 공개) (안녕하세요 경우 AOP 것 잘 작동하지만, 공공 선언없이 위에, AOP는 전혀 작동하지 않습니다. 하지만 아니요 EnableAspectJAutoProxy은 CGLIB를 사용하며 보호 된/개인 메서드 호출을 가로채는 수 있습니까? 때문에 Spring의 AOP 프레임 워크의 프록시 기반 자연
없음이 할 수없는 선언에 추가합니다. –
@ M.Deinum [스프링 부트 문서 (Aop on)] (http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-pointcuts-designators)를 확인했습니다. , 스프링 구동 [native AspectJ weaving] (http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-aj-ltw)을 사용하여 이 문제를 해결할 수는 있지만 권장하지는 않습니까? –