SpringMvc 转springboot

一、web.xml里面的配置进行改造

关于里面的SpringBoot--添加配置Servlet,Filter,listener可以看看https://blog.csdn.net/cb2474600377/article/details/54628770
这个地方我说intercepter,可以通过继承WebMvcConfigurerAdaper可以添加Converters和intercpter,首先需要建立一个Bean,然后通过复写WebMvcConfigurerAdaper的addInterceptors()实现
@Component
@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter implements Serializable {

    private static final long serialVersionUID = -7074628357528987887L;

    @Override
    public void configureMessageConverters(List> converters) {
        converters.add(restResponseHttpMessageConverter());
        converters.add(jrProtobufHttpMessageConverter());
    }

    @Bean
    public RestResponseHttpMessageConverter restResponseHttpMessageConverter(){
        return new RestResponseHttpMessageConverter();
    }
    @Bean
    public JrProtobufHttpMessageConverter jrProtobufHttpMessageConverter(){
        return new JrProtobufHttpMessageConverter();
    }
    @Bean
    public RestHandlerInterceptor restHandlerInterceptor(){
        return new RestHandlerInterceptor();
    }
    @Bean
    public AsShutServiceInterceptor asShutServiceInterceptor(){
        return new AsShutServiceInterceptor();
    }
    @Bean
    public AuthHandlerInterceptor authHandlerInterceptor(){
        return new AuthHandlerInterceptor();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        // 多个拦截器组成一个拦截器链

        // addPathPatterns 用于添加拦截规则

        // excludePathPatterns 用户排除拦截
        // 都排除了swagger路径
        registry.addInterceptor(restHandlerInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/getHelpCenter","/swagger-resources/**","/error");
        registry.addInterceptor(asShutServiceInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/h5/**","/ac/**","/captcha/captcha","/swagger-resources/**","/error");
        registry.addInterceptor(authHandlerInterceptor()).addPathPatterns("/vi/**","/v1/product/**").excludePathPatterns("/swagger-resources/**","/error");
        super.addInterceptors(registry);

    }
}


你可能感兴趣的:(微服务Springcloud,spring,boot,java,servlet)