Error con Spring boot!
Publicado por Rocio (21 intervenciones) el 17/02/2022 20:13:59
Hola! Buenas tardes. Soy nueva con Spring y me aparecio este error:
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-17 16:02:00.613 ERROR 21000 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method inicio in mx.com.gm.ControladorInicio required a bean of type 'org.springframework.ui.Model' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.ui.Model' in your configuration.
Alguien sabe a que se debe? Les dejo mi codigo en Java
package mx.com.gm;
Código
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
@SpringBootApplication
public class HolaSpringApplication {
public static void main(String[] args) {
SpringApplication.run(HolaSpringApplication.class, args);
}
}
package mx.com.gm;
import java.util.ArrayList;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import mx.com.gm.dominio.Persona;
@Controller
public class ControladorInicio {
private PersonaDao personadao;
@GetMapping("/")
@Autowired
public String inicio (Model model) {
String saludar = "Adios mundo con thymeleaf";
var personas = personadao.findAll();
model.addAttribute("personas", personas);
return "index";
}
}
package mx.com.gm.dominio;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
//import lombok.Data;
//@Data
@Entity
public class Persona implements Serializable {
private static final long SerialVersionUID= 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer ID;
private String nombre;
private String apellido;
private String email;
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getApellido() {
return apellido;
}
public void setApellido(String apellido) {
this.apellido = apellido;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
package mx.com.gm;
import org.springframework.data.repository.CrudRepository;
import mx.com.gm.dominio.Persona;
public interface PersonaDao extends CrudRepository<Persona, Integer>{
}
mi pom.xml
<?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 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.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>mx.com.gm</groupId>
<artifactId>HolaMundoSpringData</artifactId>
<version>1.0</version>
<name>HolaMundoSpringData</name>
<description>HolaMundo con Spring</description>
<properties>
<java.version>13</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</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-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properti:
spring.datasource.url=jdbc:mysql://localhost:3306/spring?zeroDateTimeBehavior=convertToNull&useSSL=false&useTimezone=true&serverTimezone=UTC&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=123777
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
Código
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bienvenido</title>
</head>
<body>
<h1>inicio</h1>
<table border= "1">
<tr>
<th> Nombre: </th>
<th> Apellido: </th>
<th> Email: </th>
</tr>
<tr th:each="persona : ${personas}">
<td th:text="${persona.nombre}">Nombre</td>
<td th:text="${persona.apellido}">Apellido</td>
<td th:text="${persona.email}">Email</td>
</tr>
</table>
</body>
</html>
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-17 16:02:00.613 ERROR 21000 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of method inicio in mx.com.gm.ControladorInicio required a bean of type 'org.springframework.ui.Model' that could not be found.
Action:
Consider defining a bean of type 'org.springframework.ui.Model' in your configuration.
Alguien sabe a que se debe? Les dejo mi codigo en Java
package mx.com.gm;
Código
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
@SpringBootApplication
public class HolaSpringApplication {
public static void main(String[] args) {
SpringApplication.run(HolaSpringApplication.class, args);
}
}
package mx.com.gm;
import java.util.ArrayList;
import java.util.Arrays;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import mx.com.gm.dominio.Persona;
@Controller
public class ControladorInicio {
private PersonaDao personadao;
@GetMapping("/")
@Autowired
public String inicio (Model model) {
String saludar = "Adios mundo con thymeleaf";
var personas = personadao.findAll();
model.addAttribute("personas", personas);
return "index";
}
}
package mx.com.gm.dominio;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
//import lombok.Data;
//@Data
@Entity
public class Persona implements Serializable {
private static final long SerialVersionUID= 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer ID;
private String nombre;
private String apellido;
private String email;
public String getNombre() {
return nombre;
}
public void setNombre(String nombre) {
this.nombre = nombre;
}
public String getApellido() {
return apellido;
}
public void setApellido(String apellido) {
this.apellido = apellido;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
package mx.com.gm;
import org.springframework.data.repository.CrudRepository;
import mx.com.gm.dominio.Persona;
public interface PersonaDao extends CrudRepository<Persona, Integer>{
}
mi pom.xml
<?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 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.2.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>mx.com.gm</groupId>
<artifactId>HolaMundoSpringData</artifactId>
<version>1.0</version>
<name>HolaMundoSpringData</name>
<description>HolaMundo con Spring</description>
<properties>
<java.version>13</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</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-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properti:
spring.datasource.url=jdbc:mysql://localhost:3306/spring?zeroDateTimeBehavior=convertToNull&useSSL=false&useTimezone=true&serverTimezone=UTC&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=123777
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
spring.jpa.properties.hibernate.format_sql=true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
Código
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bienvenido</title>
</head>
<body>
<h1>inicio</h1>
<table border= "1">
<tr>
<th> Nombre: </th>
<th> Apellido: </th>
<th> Email: </th>
</tr>
<tr th:each="persona : ${personas}">
<td th:text="${persona.nombre}">Nombre</td>
<td th:text="${persona.apellido}">Apellido</td>
<td th:text="${persona.email}">Email</td>
</tr>
</table>
</body>
</html>
Valora esta pregunta


0