[英]Spring AOP advice not getting executed
我正在嘗試執行建議,但它不起作用。 我正在嘗試在沒有應用程序上下文的情況下進行操作。
這是我的休息控制器:
package hello;
import java.util.concurrent.atomic.AtomicLong;
import aspect.exception.GreetingsNotFoundException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class GreetingController {
private static final String template = "Hello, %s!";
private final AtomicLong counter = new AtomicLong();
@RequestMapping("/greeting")
public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) {
return new Greeting(counter.incrementAndGet(),
String.format(template, name));
}
}
方面類:
@Aspect
//@ComponentScan
public class AfterThrowingException implements ThrowsAdvice {
// Obtain a suitable logger.
private static Logger logger = LoggerFactory.getLogger(AfterThrowingException.class);
@Before("execution(hello.GreetingController.greeting()")
public void logBefore(JoinPoint joinPoint){
System.out.println("Inside AfterThrowingException.logBefore()");
}
配置類:
@Configuration
@EnableAspectJAutoProxy
public class AppConfig {
@Bean
public AfterThrowingException afterThrowingException() {
return new AfterThrowingException();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.