在Spring Boot应用程序中测试Aspect @Before批注,它不起作用。没有引发错误。只是根本不起作用。这是一个非常简单的休息服务,如下所示。已经花了一段时间了,这里的任何教程和答案似乎都表明这是正确的。我的休息服务正确返回。只是来自Aspect的消息不会打印。我非常有信心我的包裹结构正确。请指教。
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
public class StuffApplication {
public static void main(String[] args) {
SpringApplication.run(StuffApplication.class, args);
}
}
@RestController
@RequestMapping("/information")
public class ContentController {
@GetMapping("/person")
public People getPerson(Model model){
log(); // expecting the aspect print to occur when I call this.
// some logic to get personList which works fine
return new People(personList);
}
public void log(){
System.out.println("This is a logger");
}
}
@Aspect
@Component
public class JsonAspect {
@Before(value = "execution(* com.example.stuff.controller.ContentController.log())")
public void printBefore(){
System.out.println("I was called before the logger"); // never prints when I call log method
}
}