Java Spring AOP建议未得到执行
我试图让建议得到执行,但它不起作用。我正在尝试在没有应用程序上下文的情况下完成它 这是我的Rest控制器:Java Spring AOP建议未得到执行,java,maven,spring-mvc,spring-aop,Java,Maven,Spring Mvc,Spring Aop,我试图让建议得到执行,但它不起作用。我正在尝试在没有应用程序上下文的情况下完成它 这是我的Rest控制器: package hello; import java.util.concurrent.atomic.AtomicLong; import aspect.exception.GreetingsNotFoundException; import org.springframework.web.bind.annotation.RequestMapping; import org.spring
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();
}
}
jointPoint.proceed();
@Before("* execution(hello.GreetingController.greeting(..)")
jointPoint.proceed();