【发布时间】:2017-03-10 17:14:48
【问题描述】:
我正在开发一个使用 Spring Boot Web 的简单 Spring Boot 应用程序。根据 Spring Boot 文档,我将 index.html 放入资源目录的模板子目录中。我在 application.properties 文件中定义了:
spring.mvc.view.prefix=classpath:/templates/
spring.mvc.view.suffix=.html
我的 WebMvcConfigurerAdapter 如下所示:
@Configuration
@EnableWebMvc
public class WebMvcConfig extends WebMvcConfigurerAdapter{
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
super.addViewControllers(registry);
}
}
我的问题是我似乎无法在http://localhost:8080 提供 index.html。 我收到以下错误: “javax.servlet.ServletException:无法解析名称为 'dispatcherServlet' 的 servlet 中名称为 'index' 的视图”。
如何在不使用控制器的情况下解决此问题?
亲切的问候, 戴夫
【问题讨论】:
-
用@Controller注释类
标签: spring spring-boot