【问题标题】:Serving static Resource with spring boot + spring security使用 Spring Boot + Spring Security 提供静态资源
【发布时间】:2016-05-04 06:20:47
【问题描述】:

我在 angularjs 应用程序上工作,并尝试使用 Spring boot 提供静态资源(我的前端)。

我使用 gulp 构建项目,我得到了这个分布结构:

  • 这是hash文件夹的内容

我的 spring 安全配置如下所示:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http
            .exceptionHandling()
            .authenticationEntryPoint(myEntryPoint());
    http
            .authorizeRequests()
            .antMatchers("/__hash__/**").permitAll() 
            .antMatchers("/views/**").permitAll()
            .antMatchers("/index.html").permitAll()
            .antMatchers("/api/**").authenticated()
            .antMatchers("/**").permitAll(); 

    http    // login configuration
            .addFilterAfter(springSecurityFilter(), BasicAuthenticationFilter.class);

    /*http
            .authorizeRequests()
            .anyRequest().authenticated();*/

    http    //logout configuration
            .logout()
            .logoutSuccessHandler(logoutHandler());

    http.csrf().disable();

}

用于提供静态内容的配置弹簧:

@Configuration
public class MyContentConfig extends WebMvcConfigurerAdapter {

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
    registry
            .addResourceHandler("/**")
            .addResourceLocations("file:///" + "c:/front/") ;
}

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("forward:/index.html");
}

}

身份验证后,我得到了 index.html 页面,但没有 css 样式,也没有 js。

当我尝试使用此 URL“https://localhost:9999/hash/styles.min.css”访问 css 时,我收到此错误:

 There was an unexpected error (type=Not Acceptable, status=406).
 Could not find acceptable representation

【问题讨论】:

  • 您正在使用 HTTPS 访问您的服务器资源.. 您的 .properties中是否有有效的 SSL 配置> 文件?
  • 是的。我已将 tomcat 配置为使用 SSL
  • 您尝试过使用 HTTP 吗?

标签: java angularjs spring spring-security gulp


【解决方案1】:

我解决了这个问题。它与“spring-cloud-config-server”有关。我只是删除了这个配置: org.springframework.cloud 弹簧云配置服务器

【讨论】:

    【解决方案2】:

    您正在通过 http 加载 livereload.js。如果您使用的是 https,则所有资源都必须通过 https 加载。 所以通过 https 加载 livereload.js

    【讨论】:

      猜你喜欢
      • 2014-09-15
      • 1970-01-01
      • 2017-11-02
      • 1970-01-01
      • 1970-01-01
      • 2016-10-01
      • 2015-08-21
      • 2021-10-11
      • 1970-01-01
      相关资源
      最近更新 更多