我在angularjs应用程序上工作,我尝试使用Spring启动服务静态资源(我的前端) .
我使用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();
}
用于提供静态内容的配置 spring :
@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
2 回答
您正在 http 上载 livereload.js . 如果您使用的是https,则必须通过https加载所有资源 . 所以 load livereload.js over https .
我解决了这个问题 . 它与“spring-cloud-config-server”有关 . 我只是删除了这个配置:org.springframework.cloud spring-cloud-config-server