圆形视图路径错误Spring启动

我对Spring很新。 我正在尝试使用Spring Boot构建一个MVC应用程序,它显示了一个产品列表。 但我收到以下错误:

javax.servlet.ServletException:循环视图路径[products]:将再次调度回当前处理程序URL [/ products]。 检查您的ViewResolver设置! (提示:由于生成默认视图名称,这可能是未指定视图的结果。)

这是控制器:

package com.springframeworkguru.controllers; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import com.springframeworkguru.services.ProductService; @Controller public class ProductController { private ProductService productService; @Autowired public void setProductService(ProductService productService) { this.productService = productService; } @RequestMapping("/products") public String listProducts(Model model){ model.addAttribute("products", productService.listAllProducts()); return "products"; } } 

这是主要类:

 package com.springframeworkguru; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.SpringBootServletInitializer; import com.springframeworkguru.controllers.ProductController; @SpringBootApplication public class SpringmvcApplication extends SpringBootServletInitializer{ public static void main(String[] args) { SpringApplication.run(SpringmvcApplication.class, args); } } 

products.html

    Spring Core Online Tutorial - List Products       

Product List

Id Description Price Image URL List
View

products.html位于/static文件夹中。 另外,我正在使用Eclipse Kepler。

添加spring-boot-starter-thymeleaf依赖解决了这个问题。

所以将它添加到你的pom.xml文件中:

  org.springframework.boot spring-boot-starter-thymeleaf  

products.html是/ static文件夹

默认情况下,Spring Boot将在类路径的templates目录中查找Thymeleaf模板。 所以将您的products.html移动到src/main/resources/templates目录。 您可以在Spring Boot文档中阅读有关模板引擎和Spring Boot的更多信息:

当您使用默认配置的百万美元模板引擎时,您的模板将自动从src/main/resources/templates

此外, static目录是您应该放置静态内容而不是模板的位置。

pom.xml添加以下依赖项

   org.springframework.boot spring-boot-starter-thymeleaf 1.4.0.RELEASE  

可以在mvnrepository上找到最新版本

将“product.ftl”重命名为“product s .ftl”。