[英]Serving static Resource with spring boot + spring security
我在angularjs應用程序上工作,我嘗試通過Spring Boot服務靜態資源(前端)。
我的春季安全配置如下所示:
@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
您正在通過http加載livereload.js 。 如果使用https,則必須通過https加載所有資源。 因此, 通過https加載livereload.js 。
我解決了這個問題。 它與“ spring-cloud-config-server”有關。 我只是刪除此配置:org.springframework.cloud spring-cloud-config-server
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.