java - 在建议没有被执行之前
问题描述
我正在尝试调用之前的建议,但没有使用定义的切入点执行相同的建议
我在 com.my.ms 包中有主要应用程序
@SpringBootApplication
@EnableAspectJAutoProxy
public class TemplateServiceApplication {
public static void main(String[] args) {
SpringApplication.run(TemplateServiceApplication.class, args);
}
}
在包 com.my.ms.tst.advices 我有之前的建议
@Aspect
public class ValidatingAdvices {
@Before(value = "execution(* com.my.ms.tst.api.*.get*(..))")
public void validateKey(JoinPoint joinPoint) throws Throwable {
System.out.println("Executing the before advice");
}
}
控制器位于 com.my.ms.tst.api 包中
@Controller
@RequestMapping("/ts")
public class MainController {
@GetMapping("/check")
public String getTemp() throws IOException {
return "five";
}
}
但是下面的建议没有得到执行
解决方案
您在ValidatingAdvices中添加 @Configuration 注释。
@Configuration
@Aspect
public class ValidatingAdvices {
@Before(value = "execution(* com.my.ms.tst.api.*.get*(..))")
public void validateKey(JoinPoint joinPoint) throws Throwable {
System.out.println("Executing the before advice");
}
}
推荐阅读
- php - 如何在 PHP/Laravel 中 POST 后保留克隆的字段值
- ios - 结合超时链接
- reactjs - 开玩笑:接听电话数:0
- jquery - 我的 jquery 代码在 safari 旧版本中不支持,但在最新版本和 chrome 上也可以正常工作
- node.js - 服务器响应不需要的响应?
- python-3.x - Python GEKKO 中基于 ODE 或 PDE 的生态系统模型最合适的求解方法是什么?
- python - 如何将用户输入完全转换为用于训练分类器的处理数据?我想对用户输入文本进行情感分析
- python - 向量化双 for 循环
- javascript - Java 通过将零添加到以下格式 XX.xxxxxx 来转换用户的输入
- json - 从 json 文件在 tableview 中打开 pdf