Spring 不同的安全实现方式都以相同的错误告终
我已经实现了一个结合了Spring 不同的安全实现方式都以相同的错误告终,spring,security,spring-security,static-content,Spring,Security,Spring Security,Static Content,我已经实现了一个结合了springboot和angular4的应用程序。我将所有Angular文件放在/resources/static目录下: 然后我添加到Spring Security类: @Configuration @EnableWebMvc @ComponentScan("com.inventory") public class WebConfig extends WebMvcConfigurerAdapter { @Override public void add
springboot
和angular4
的应用程序。我将所有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");
}
}
以及:
似乎一切都应该起作用。不幸的是,每当我运行我的应用程序时,它都会引发异常:
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 boot时,通常不必手动配置资源处理程序,Spring boot将自动从以下位置加载内容:
- /静止的
- /公开的
- /资源
- /META-INF/资源
请参见,如果您想像您的案例那样提供自定义位置,那么请在处理程序中包含此位置:.addResourceHandler(“/resources/**”),因此我改为:
@Override public void addResourceHandlers(ResourceHandlerRegistry registry){registry.addResourceHandler(“/resources/**”、“/”、“/#/”)。addResourceLocations(“/resources/static/index.html”、“/resources/static/index.html”、“/resources/static/index.html”)}
它抛出了一个意外的错误(type=Not Found,status=404)。没有可用的消息我认为你不能使用#登录你的url,这并不意味着要在服务器中传递。
@Controller
public class ViewController {
@RequestMapping(value = "/#/")
public String index() {
return "forward:/index.html";
}
@RequestMapping(value = "/")
public String home() {
return "forward:/index.html";
}
}