V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
fangch
V2EX  ›  问与答

江湖救急, springboot 配置拦截器静态资源的配置老是不生效,弄了一天了,哎!

  •  
  •   fangch · Apr 17, 2019 · 5644 views
    This topic created in 2575 days ago, the information mentioned may be changed or developed.

    springboot 的版本是
    2.1.4

    application.yml 中的配置是:
    spring:mvc:static-path-pattern:/static/**

    mvc 的配置是:
    @Configuration
    public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    private SessionInterceptor sessionInterceptor;
    
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
    }
    
    @Override
    public void addInterceptors(InterceptorRegistry registry){
    
        registry.addInterceptor(sessionInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns("/static/**","/login","/js/**");
    
    }
    
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/static/**");
    }
    

    }

    前台访问的的静态资源的链接是;
    http://localhost:8081/js/jquery-3.3.1.min.js ,这个是已经配置了排除了,但是为什么还是被拦截!

    说明:
    配置中 /login 这个请求已经拦截已经生效了,但是为什么静态资源没有生效,希望大佬帮忙看看有哪些地方错了!

    Supplement 1  ·  Apr 17, 2019
    已经解决
    原因:
    springboot 添加拦截器之后,不认 springboot 之前默认访问的 static 文件夹,访问应该使用 http://localhost:8081/static/js/jquery.min.js,加上 static 文件夹即可
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2464 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 15:42 · PVG 23:42 · LAX 08:42 · JFK 11:42
    ♥ Do have faith in what you're doing.