【发布时间】:2019-05-13 10:09:27
【问题描述】:
我在我的 Spring Boot 应用程序的资源文件夹中创建了一个静态文件夹。在静态文件夹中,我有一个 index.html 文件。然后我将此添加到我的配置中:
protected void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/");
}
现在我可以在 localhost:8080/index.html 访问 index.html,但我想做的是在 localhost:8080 访问它。我已经试过了:
@Override
protected void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("forward:/index.html");
}
但我知道 ServletDispatcher 无法识别“forward:/index.html”。有人可以帮我弄这个吗?提前致谢。
编辑
我通过删除所有自定义配置解决了这个问题,因此我的应用可以使用默认配置。在我的特殊情况下,这对我有用,但知道如何使用自定义配置来实现这一点也不错。所以这个问题还是悬而未决,欢迎大家就这个问题提出一些意见。
【问题讨论】:
-
查看这个 SO 问题stackoverflow.com/questions/42393211/… 的答案,这也可能有用spring.io/blog/2013/12/19/…
标签: spring spring-boot