Spring Boot Appのインターセプタを有効にするために、カスタマイズ可能な注釈を書くことは可能ですか?Springブートアプリケーションでカスタムインターセプトアノテーションを作成するにはどうすればよいですか?
これは私のコード、
設定
@Configuration
public class CustomConfig extends WebMvcConfigurerAdapter {
@Autowired
CustomInterceptor interceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(interceptor);
}
}
インターセプタ
@Component
public class CustomInterceptor implements HandlerInterceptor {
@Override
public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
throws Exception {
System.err.println("Executed!!!afterCompletion");
}
@Override
public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
throws Exception {
System.err.println("Executed!!!postHandle");
}
@Override
public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
// TODO Auto-generated method stub
return true;
}
}
カスタム注釈
です私はこの注釈@EnableCustomConfig
が
@SpringBootApplication
@EnableAutoConfiguration
@EnableCustomConfig
public class CustomEnableApplication {
public static void main(String[] args) {
SpringApplication.run(CustomEnableApplication.class, args);
}
}
は春に達成することが可能。これは、メインクラスに存在している場合にのみ、このインタセプタを有効にする
@Documented
@Retention(RUNTIME)
@Target(TYPE)
@Import(CustomConfig.class)
public @interface EnableCustomConfig {
}
ブート?はいの場合は、どうか教えてください。
私の例はあなたの質問に答えましたか? –