Vue circulaire erreur de chemin d'accès Printemps de démarrage
Je suis très nouveau pour le Printemps. Je suis en train de construire une application MVC à l'aide de Printemps de Démarrage qui affiche une liste de produits. Mais j'obtiens l'erreur ci-dessous:
javax.servlet.ServletException: Circulaire chemin de la vue [produits]: serait
la répartition de l'actuel gestionnaire d'URL [/produits] à nouveau. Vérifiez votre
ViewResolver d'installation! (Indice: C'est peut-être le résultat d'un quelconque
vue, en raison de l'affichage par défaut de la génération de nom.)
Ici est de contrôleur:
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";
}
}
C'est la classe principale:
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);
}
}
et products.html
:
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<title>Spring Core Online Tutorial - List Products</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link href="http://cdn.jsdelivr.net/webjars/bootstrap/3.3.4/css/bootstrap.min.css"
th:href="@{/webjars/bootstrap/3.3.5/css/bootstrap.min.css}"
rel="stylesheet" media="screen"/>
<script src="http://cdn.jsdelivr.net/webjars/jquery/2.1.4/jquery.min.js"
th:src="@{/webjars/jquery/2.1.4/jquery.min.js}"></script>
<link href="../css/spring-core.css"
th:href="@{css/spring-core.css}" rel="stylesheet" media="screen"/>
</head>
<body>
<div class="container">
<div th:if="${not #lists.isEmpty(products)}">
<h2>Product List</h2>
<table class="table table-striped">
<tr>
<th>Id</th>
<th>Description</th>
<th>Price</th>
<th>Image URL</th>
<th>List</th>
</tr>
<tr th:each="product : ${products}">
<td th:text="${product.id}"></td>
<td th:text="${product.description}"></td>
<td th:text="${product.price}"></td>
<td th:text="${product.imageUrl}"></td>
<td><a th:href="${'/product/' + product.id}">View</a> </td>
</tr>
</table>
</div>
</div>
</body>
</html>
La products.html
est dans /static
dossier. Aussi, je suis en utilisant Eclipse Kepler.
OriginalL'auteur sohan | 2016-04-18
Vous devez vous connecter pour publier un commentaire.
Ajoutant
spring-boot-starter-thymeleaf
dépendance résolu le problème.Afin de l'ajouter à votre pom.xml fichier:
Il m'a vraiment aidé. @sohan, pouvez-vous accepter cette réponse?
OriginalL'auteur
Par défaut, Spring Boot vous cherchez Thymeleaf modèles dans
templates
répertoire sur le chemin de la classe. Déplacez votreproducts.html
àsrc/main/resources/templates
répertoire. Vous pouvez lire plus sur les moteurs de template et le Printemps Boot sur le Printemps De Démarrage De La Documentation:Aussi,
static
répertoire où vous devez mettre votre Contenu Statique, pas des modèles.Avez-vous d'ajouter le
spring-boot-starter-thymeleaf
dépendance?Merci beaucoup. Il a travaillé après l'ajout de printemps-amorçage-starter-thymeleaf, printemps-amorçage-starter-web de la dépendance.
Merci, Il a également travaillé après l'ajout de printemps-amorçage-starter-thymeleaf et printemps-amorçage-starter-web.
OriginalL'auteur
Ajouter la dépendance suivant dans
pom.xml
La dernière version peut être trouvée sur mvnrepository
OriginalL'auteur
Renommer ".ftl" à "produits.ftl".
OriginalL'auteur