Spring - Intercepting bean creation and injecting custom proxy

后端 未结 4 1613
孤独总比滥情好
孤独总比滥情好 2021-02-13 16:07

I have a @Controller with @Autowired fields and handler methods that I want to annotate with custom annotations.

For example,

         


        
4条回答
  •  终归单人心
    2021-02-13 16:38

    Taking into account your comment under the question all you need is HandlerInterceptor.

    http://static.springsource.org/spring/docs/3.2.x/javadoc-api/org/springframework/web/servlet/HandlerInterceptor.html

    You need to implement that interface and add it to your configuration, for example:

    
        
    
    

    This interface provides method preHanlde, which has request, response and HandlerMethod. To check if the method is annotated just try this:

    HandlerMethod method = (HandlerMethod) handler;
    OnlyIfXYZ customAnnotation = method.getMethodAnnotation(OnlyIfXYZ.class);
    

提交回复
热议问题