【发布时间】:2017-11-14 22:54:02
【问题描述】:
我已经实现了一个结合Spring Boot 和Angular 4 的应用程序。我把所有Angular文件放在/resources/static目录下:
然后我添加到Spring Security 类:
@Configuration
@EnableWebMvc
@ComponentScan("com.inventory")
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/static/**")
.addResourceLocations("classpath:/resources/static/");
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index.html");
}
}
和:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private UserDetailsService userDetailsService;
@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordencoder());
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated();
}
似乎一切都应该工作。不幸的是,每当我运行我的应用程序时,它都会引发异常:
There was an unexpected error (type=Internal Server Error, status=500).
Could not resolve view with name 'index.html' in servlet with name 'dispatcherServlet'.
当然我尝试了不同的解决方案,比如添加这个:
@Controller
public class ViewController {
@RequestMapping(value = "/#/")
public String index() {
return "forward:/index.html";
}
@RequestMapping(value = "/")
public String home() {
return "forward:/index.html";
}
}
但是没有任何效果。有谁知道我还能做什么?
【问题讨论】:
标签: spring security spring-security static-content