美文网首页
spring boot配置static的resource和int

spring boot配置static的resource和int

作者: java修炼 | 来源:发表于2018-11-21 11:03 被阅读0次

    spring boot的常用配置,记录保存
    1、继承WebMvcConfigurerAdapter
    2、覆盖父类方法

    @Configuration
    public class WebConfiguration extends WebMvcConfigurerAdapter{
    
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/**")
                    .addResourceLocations("classpath:/static/");
            super.addResourceHandlers(registry);
        }
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**");
            registry.addInterceptor(new PermissionInterceptor()).addPathPatterns("/**");
            super.addInterceptors(registry);
        }
    

    spring mvc 5.0以后类WebMvcConfigurerAdapter废弃,只需要实现WebMvcConfigurer即可

    @Configuration
    public class WebConfiguration implements WebMvcConfigurer{
    
        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/**")
                    .addResourceLocations("classpath:/static/");
        }
    
        @Override
        public void addInterceptors(InterceptorRegistry registry) {
            registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/**");
            registry.addInterceptor(new PermissionInterceptor()).addPathPatterns("/**");
        }
    

    相关文章

      网友评论

          本文标题:spring boot配置static的resource和int

          本文链接:https://www.haomeiwen.com/subject/bomqqqtx.html