springboot里面写servlet,自定义注解不生效

springboot里面写servlet,@WebServlet后,添加自定义注解@interface的注解不生效,无法进入日志切面。


@Log(operModule = "登录模块1",operType = "登录日志查询1")
@WebServlet(name ="ajh", urlPatterns ="/ajh")  
public class ajh extends HttpServlet {
    @Override
    @Log(operModule = "登录模块2",operType = "登录日志查询2")
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

类前面和dopost前面都试着添加,均不生效。


public @interface Log {

    String operModule() default "";//操作模块
    String operType() default "";//操作类型
}

Spring AOP 拦截的是 bean 方法的执行,你定义的 Servlet 不是一个 bean ,自然无法拦截,可以尝试把 Servlet 定义为 bean,然后使用 API 的方式添加 Servlet。