【发布时间】:2016-06-14 17:00:33
【问题描述】:
我正在开发单页 Angular 应用程序,现在我需要为我的客户提供静态 html 索引页面,这就是我所做的:
我正在使用这个配置:
@Configuration
@EnableAutoConfiguration
@EnableWebMvc
@EnableCaching
@ComponentScan(basePackages = "com.example.*")
public class DemoJPAConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/static/**").addResourceLocations("/static/");
}
.
.
.
控制器: */
@Controller
public class MainController {
//mapping for index html template
@RequestMapping("/")
public String getIndexPage() {
return "static/app/index.html";
}
//mapping for all other templates
@RequestMapping("/templates/{name}/{component}")
public String getPage(@PathVariable("name") String name,
@PathVariable("component") String component) {
return "/static/"+name + "/"+component+".html";
}
我用的是spring boot 1.3.2
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.2.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
我收到 500 服务器错误状态并显示此消息
无法解析 servlet 中名称为“static/app/index.html”的视图 名称为“dispatcherServlet”
【问题讨论】:
标签: java spring spring-mvc spring-boot