elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  Error con Spring boot! Ayuda
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Error con Spring boot! Ayuda  (Leído 3,140 veces)
Ruusa

Desconectado Desconectado

Mensajes: 32


Ver Perfil
Error con Spring boot! Ayuda
« en: 17 Febrero 2022, 20:12 pm »

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

Código
  1. package mx.com.gm;
  2.  
  3. import org.springframework.boot.SpringApplication;
  4. import org.springframework.boot.autoconfigure.SpringBootApplication;
  5. import org.springframework.context.annotation.Configuration;
  6.  
  7. @SpringBootApplication
  8. public class HolaSpringApplication {
  9.  
  10. public static void main(String[] args) {
  11. SpringApplication.run(HolaSpringApplication.class, args);
  12. }
  13.  
  14. }
  15.  
  16.  
  17. package mx.com.gm;
  18.  
  19.  
  20. import java.util.ArrayList;
  21. import java.util.Arrays;
  22.  
  23. import org.springframework.beans.factory.annotation.Autowired;
  24.  
  25. import org.springframework.beans.factory.annotation.Value;
  26. import org.springframework.context.annotation.Bean;
  27. import org.springframework.stereotype.Controller;
  28. import org.springframework.ui.Model;
  29. import org.springframework.web.bind.annotation.GetMapping;
  30. import org.springframework.web.bind.annotation.ModelAttribute;
  31.  
  32. import lombok.extern.java.Log;
  33. import lombok.extern.slf4j.Slf4j;
  34. import mx.com.gm.dominio.Persona;
  35.  
  36.  
  37.  
  38. @Controller
  39.  
  40.  
  41. public class ControladorInicio {
  42.  
  43.  
  44.  
  45.   private PersonaDao personadao;
  46.  
  47. @GetMapping("/")
  48. @Autowired
  49.  
  50.  
  51. public String inicio (Model model) {
  52. String saludar = "Adios mundo con thymeleaf";
  53.  
  54. var personas = personadao.findAll();
  55.  
  56. model.addAttribute("personas", personas);
  57.  
  58.  
  59.  
  60.  
  61.  
  62. return "index";
  63.  
  64. }
  65. }
  66.  
  67.  
  68. package mx.com.gm.dominio;
  69.  
  70. import java.io.Serializable;
  71.  
  72. import javax.persistence.Entity;
  73. import javax.persistence.GeneratedValue;
  74. import javax.persistence.GenerationType;
  75. import javax.persistence.Id;
  76.  
  77. //import lombok.Data;
  78.  
  79. //@Data
  80.  
  81.  
  82. public class Persona implements Serializable {
  83.  
  84. private static final long SerialVersionUID= 1L;
  85.  
  86. @Id
  87. @GeneratedValue(strategy = GenerationType.IDENTITY)
  88.    private Integer ID;
  89. private String nombre;
  90. private String apellido;
  91. private String email;
  92.  
  93. public String getNombre() {
  94. return nombre;
  95. }
  96. public void setNombre(String nombre) {
  97. this.nombre = nombre;
  98. }
  99. public String getApellido() {
  100. return apellido;
  101. }
  102. public void setApellido(String apellido) {
  103. this.apellido = apellido;
  104. }
  105. public String getEmail() {
  106. return email;
  107. }
  108. public void setEmail(String email) {
  109. this.email = email;
  110. }
  111.  
  112.  
  113.  
  114.  
  115. }
  116.  
  117. package mx.com.gm;
  118.  
  119. import org.springframework.data.repository.CrudRepository;
  120.  
  121. import mx.com.gm.dominio.Persona;
  122.  
  123. public interface PersonaDao extends CrudRepository<Persona, Integer>{
  124.  
  125.  
  126. }
  127.  
  128.  
  129. mi pom.xml
  130. <?xml version="1.0" encoding="UTF-8"?>
  131. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  132.         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  133.    <modelVersion>4.0.0</modelVersion>
  134.    <parent>
  135.        <groupId>org.springframework.boot</groupId>
  136.        <artifactId>spring-boot-starter-parent</artifactId>
  137.        <version>2.2.4.RELEASE</version>
  138.        <relativePath/> <!-- lookup parent from repository -->
  139.    </parent>
  140.    <groupId>mx.com.gm</groupId>
  141.    <artifactId>HolaMundoSpringData</artifactId>
  142.    <version>1.0</version>
  143.    <name>HolaMundoSpringData</name>
  144.    <description>HolaMundo con Spring</description>
  145.  
  146.    <properties>
  147.        <java.version>13</java.version>
  148.    </properties>
  149.  
  150.    <dependencies>
  151.        <dependency>
  152.            <groupId>org.springframework.boot</groupId>
  153.            <artifactId>spring-boot-starter-thymeleaf</artifactId>
  154.        </dependency>
  155.        <dependency>
  156.            <groupId>org.springframework.boot</groupId>
  157.            <artifactId>spring-boot-starter-web</artifactId>
  158.        </dependency>
  159.        <dependency>
  160.            <groupId>org.springframework.boot</groupId>
  161.            <artifactId>spring-boot-devtools</artifactId>
  162.            <scope>runtime</scope>
  163.            <optional>true</optional>
  164.        </dependency>
  165.        <dependency>
  166.            <groupId>org.projectlombok</groupId>
  167.            <artifactId>lombok</artifactId>
  168.            <optional>true</optional>
  169.        </dependency>
  170.        <dependency>
  171.            <groupId>mysql</groupId>
  172.            <artifactId>mysql-connector-java</artifactId>
  173.            <scope>runtime</scope>
  174.        </dependency>
  175.        <dependency>
  176.            <groupId>org.springframework.boot</groupId>
  177.            <artifactId>spring-boot-starter-data-jpa</artifactId>
  178.        </dependency>
  179.        <dependency>
  180.            <groupId>org.springframework.boot</groupId>
  181.            <artifactId>spring-boot-starter-test</artifactId>
  182.            <scope>test</scope>
  183.            <exclusions>
  184.                <exclusion>
  185.                    <groupId>org.junit.vintage</groupId>
  186.                    <artifactId>junit-vintage-engine</artifactId>
  187.                </exclusion>
  188.            </exclusions>
  189.        </dependency>
  190.    </dependencies>
  191.  
  192.    <build>
  193.        <plugins>
  194.            <plugin>
  195.                <groupId>org.springframework.boot</groupId>
  196.                <artifactId>spring-boot-maven-plugin</artifactId>
  197.            </plugin>
  198.        </plugins>
  199.    </build>
  200.  
  201. </project>
  202.  
  203.  
  204. application.properti:
  205.  
  206. spring.datasource.url=jdbc:mysql://localhost:3306/spring?zeroDateTimeBehavior=convertToNull&useSSL=false&useTimezone=true&serverTimezone=UTC&allowPublicKeyRetrieval=true
  207. spring.datasource.username=root
  208. spring.datasource.password=123777
  209. spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
  210. spring.jpa.database-platform=org.hibernate.dialect.MySQL8Dialect
  211. spring.jpa.properties.hibernate.format_sql=true
  212. logging.level.org.hibernate.SQL=DEBUG
  213. logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
  214.  
  215.  


Código
  1. <!DOCTYPE html>
  2. <html xmlns:th="http://www.thymeleaf.org">
  3.    <meta charset="UTF-8">
  4.    <meta http-equiv="X-UA-Compatible" content="IE=edge">
  5.    <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.    <title>Bienvenido</title>
  7. </head>
  8.    <h1>inicio</h1>
  9.  
  10.  
  11.   <table border= "1">
  12.    <tr>
  13.        <th> Nombre: </th>
  14.        <th> Apellido: </th>
  15.        <th> Email: </th>
  16.    </tr>
  17.  
  18.    <tr th:each="persona : ${personas}">
  19.  
  20.     <td th:text="${persona.nombre}">Nombre</td>
  21.     <td th:text="${persona.apellido}">Apellido</td>
  22.    <td th:text="${persona.email}">Email</td>
  23.  
  24.  
  25.    </tr>
  26.    </table>
  27.  
  28.  
  29. </body>
  30. </html>
  31.  


En línea

rub'n


Desconectado Desconectado

Mensajes: 1.217


(e -> λ("live now")); tatuar -> λ("α");


Ver Perfil WWW
Re: Error con Spring boot! Ayuda
« Respuesta #1 en: 25 Febrero 2022, 22:48 pm »

mmm no me gusta Thymeleaf, me parece perdidad de tiempo pero.

Quien es Model ? hazle inyeccion por contructor. o marcala con @Autowired en la clase ControladorInicio

* Estas declarando un endpoint en / que muestra el html del thymeleaf ese. please usa Vaadin Flow no pierdas el tiempo con esto.


Código
  1. @Controller
  2. @RequiredArgsConstructor
  3. public class ControladorInicio {
  4.  
  5.        private final PersonaDao personadao;
  6.        private final Model model;
  7.  
  8. @GetMapping("/")
  9. public String inicio () {
  10. String saludar = "Adios mundo con thymeleaf";
  11. var personas = personadao.findAll();
  12. model.addAttribute("personas", personas);
  13. return "index";
  14. }
  15.  
  16. }

Algo asi, intenta formatear para la proxima soci@


« Última modificación: 25 Febrero 2022, 23:22 pm por rub'n » En línea



rubn0x52.com KNOWLEDGE  SHOULD BE FREE.
If you don't have time to read, you don't have the time (or the tools) to write, Simple as that. Stephen ki
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
Crud en Spring Boot con Modales, Java, Spring Boot thymeleaf.
Desarrollo Web
Beginner Web 0 3,357 Último mensaje 2 Marzo 2021, 03:02 am
por Beginner Web
algun curso de spring boot?
Desarrollo Web
Beginner Web 1 2,368 Último mensaje 13 Marzo 2021, 10:13 am
por [u]nsigned
favicon spring boot
Desarrollo Web
Beginner Web 2 2,944 Último mensaje 25 Abril 2021, 03:11 am
por Beginner Web
Spring Boot Crud
Java
thejax 2 3,153 Último mensaje 14 Mayo 2021, 05:32 am
por thejax
spring boot, css proteccion
Desarrollo Web
Beginner Web 2 2,843 Último mensaje 25 Enero 2022, 17:26 pm
por Danielㅤ
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines