Good morning,
I'm trying to write a simple web app with Spring and MVC, in the console it's all good but when I try to get the home page from the url the browser gives me the Whitelabel Error Page with error 404.
This is my controller:
package com.beanspring.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.beanspring.model.Alimento;
import com.beanspring.model.GiornoDiDieta;
import com.beanspring.service.alimentoService;
import com.beanspring.service.giornoDiDietaService;
u/Controller
u/RequestMapping(value ="/dieta")
public class DietaController {
u/Autowired
alimentoService alService;
u/Autowired
giornoDiDietaService giornoService;
u/RequestMapping(value ="/home", method = RequestMethod.GET )
public String creaHome(Model model)
{
model.addAttribute("listaAlimenti", alService.getAllAlimenti());
System.out.println("ECCOMI");
return "Home";
}
}
Home.html is in src/main/resources/templates and it shows as I expect in a browser if I open it directly.
The Spring console shows no error and it even prints "ECCOMI", so the url "localhost:8080/dieta/home" gets the method.
This is my file POM, I feel the error is in there.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="[http://maven.apache.org/POM/4.0.0](http://maven.apache.org/POM/4.0.0) [https://maven.apache.org/xsd/maven-4.0.0.xsd](https://maven.apache.org/xsd/maven-4.0.0.xsd)">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.0</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.slide</groupId>
<artifactId>dieta-2</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dieta-2</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>16</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Will you help me, please?
Aucun commentaire:
Enregistrer un commentaire