1. 程式人生 > >springboot中新增攔截器,mapping等的方法

springboot中新增攔截器,mapping等的方法

@Configuration
public class WebJavaBeanConfiguration {
    /**
     * 日誌攔截器
     */
    @Autowired
    private LogInterceptor logInterceptor;

    /**
     * 例項化WebMvcConfigurer介面
     *
     * @return
     */
    @Bean
    public WebMvcConfigurer webMvcConfigurer() {
        return new WebMvcConfigurer() {
            /**
             * 新增攔截器
             * @param registry
             */
            @Override
            public void addInterceptors(InterceptorRegistry registry) {
                registry.addInterceptor(logInterceptor).addPathPatterns("/**");
            }
        };
    }
}