0

tengo este proyecto de springboot que no inicia por errores, lo estoy haciendo de un curso y segui unos tutoriales al pie de la letra pero me da este error y no se que tengo que corregir

Aca esta el codigo para que las puedan ver, gracias

Application.java:

@SpringBootApplication
public class WpApplication {

    public static void main(String[] args) {
        SpringApplication.run(WpApplication.class, args);
    }

}

controller:

@RestController
@RequestMapping("persona") //localhost:8080/persona
@CrossOrigin(origins = "http://localhost:4200") //se vincula con Angular en el front end
public class PersonaController {
    
    @Autowired // injecta la dependencia con cableado
    public PersonaService persoServ;
    
    
    
    @GetMapping("/lista")
    @ResponseBody
    public List <Persona> verPersonas(){
        return persoServ.verPersonas();
    }
    
    @GetMapping ("/ver/{id}")
    @ResponseBody
    public Persona verPersona(@PathVariable int id){
        return persoServ.buscarPersona(id);
    }
    
    //@PostMapping("/crear")
    public String agregarPersona (@RequestBody Persona pers){
        persoServ.crearPersona(pers);
        return "Persona creada";
    }
    
    @DeleteMapping("/borrar/{id}") 
    public String eliminarPersona(@PathVariable int id){
        persoServ.borrarPersona(id);
        return "Persona borrada";
    }
    
    @PutMapping("/editar")
    public void editarPersona(@RequestBody Persona pers){
        persoServ.editarPersona(pers);
    }
    
}

entity:

@Entity
public class Persona {
    
    // crear variables
    @Id // anotation id
    @GeneratedValue(strategy=GenerationType.IDENTITY) //Incremento automatico de valor, identity esl la forma de incrementar
    private int id;
    
    //@NotNull //no es necesario
    //@Size(min =1,max=50,message="longitud incorrecta")
    private String nombres;
    private String apellido;
    
    @Temporal(TemporalType.DATE) //tipo dato fecha   jakarta.persistance.Temporaltype.DATE
    private Date fechaNac;
    
    @Lob // cambias el string a long para textos mas de 255 caracteres o @Size(min = 1 , max = 50, message = "no cumple con la longitud")
    private String sobreMi;
    private String urlImg;
    
    
    //constructor vacio
    public Persona() {
    }

    public Persona(int id, String nombres, String apellido, Date fechaNac, String sobreMi, String urlImg) {
        this.id = id;
        this.nombres = nombres;
        this.apellido = apellido;
        this.fechaNac = fechaNac;
        this.sobreMi = sobreMi;
        this.urlImg = urlImg;
    }
    
    
    
}

repository:

@Repository
public interface PersonaRepository extends JpaRepository <Persona, Integer>{ //extender de Jpa y Persona
    //metodos extras de JPA
}

service:

@Service //anotacion servicio
@Transactional //asistencia de datos
public class PersonaService {
    @Autowired 
    public PersonaRepository persoRepo;
    
    //@Override 
    public List<Persona> verPersonas(){
        List<Persona> listaPersonas=persoRepo.findAll(); //metodos JPA mostrar todo
        return listaPersonas;
    }
     
    
    public void crearPersona(Persona perso){
        persoRepo.save(perso);
    }
    
    public void editarPersona(Persona perso){
        persoRepo.save(perso);
    }
    
    public void borrarPersona(int id){
        persoRepo.deleteById(id);
    }
    
    public Persona buscarPersona(int id){
        Persona perso = persoRepo.findById(id).orElse(null); // si no encuentra la id devuelve null
        return perso;
    }
}

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>3.0.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.portfolio</groupId>
    <artifactId>wp</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>wp</name>
    <description>backend proyecto argentinaprograma</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <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>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>com.h2database</groupId>
            <artifactId>h2</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
                <dependency>
                        <groupId>jakarta.persistence</groupId>
                        <artifactId>jakarta.persistence-api</artifactId>
                </dependency> 
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

application.properties:

spring.jpa.hibernate.ddl-auto=update
spring.datasource.url= jdbc=mysql://localhost:3307/mydb?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

 

esto devuelve cuando le doy a run:

2023-04-06T01:34:27.698-03:00 INFO 5576 --- [ restartedMain] com.portfolio.wp.WpApplication : Starting WpApplication using Java 17.0.5 with PID 5576 (C:\Users\peter\OneDrive\Escritorio\YoProgramo3\wp\target\classes started by peter in C:\Users\peter\OneDrive\Escritorio\YoProgramo3\wp)

2023-04-06T01:34:27.704-03:00 INFO 5576 --- [ restartedMain] com.portfolio.wp.WpApplication : No active profile set, falling back to 1 default profile: "default"

2023-04-06T01:34:27.788-03:00 INFO 5576 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : Devtools property defaults active! Set 'spring.devtools.add-properties' to 'false' to disable

2023-04-06T01:34:27.789-03:00 INFO 5576 --- [ restartedMain] .e.DevToolsPropertyDefaultsPostProcessor : For additional web related logging consider setting the 'logging.level.web' property to 'DEBUG'

2023-04-06T01:34:28.712-03:00 INFO 5576 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2023-04-06T01:34:28.801-03:00 INFO 5576 --- [ restartedMain] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 79 ms. Found 1 JPA repository interfaces. 2023-04-06T01:34:29.749-03:00 INFO 5576 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8080 (http) 2023-04-06T01:34:29.764-03:00 INFO 5576 --- [ restartedMain] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2023-04-06T01:34:29.764-03:00 INFO 5576 --- [ restartedMain] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.5]

2023-04-06T01:34:29.866-03:00 INFO 5576 --- [ restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2023-04-06T01:34:29.866-03:00 INFO 5576 --- [ restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2075 ms

2023-04-06T01:34:29.922-03:00 INFO 5576 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2023-04-06T01:34:30.131-03:00 INFO 5576 --- [ restartedMain] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2023-04-06T01:34:30.206-03:00 INFO 5576 --- [ restartedMain] org.hibernate.Version
: HHH000412: Hibernate ORM core version 6.1.7.Final

2023-04-06T01:34:30.630-03:00 INFO 5576 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...

2023-04-06T01:34:30.631-03:00 WARN 5576 --- [ restartedMain] o.h.e.j.e.i.JdbcEnvironmentInitiator : HHH000342: Could not obtain connection to query metadata

java.lang.RuntimeException: Driver org.h2.Driver claims to not accept jdbcUrl, jdbc=mysql://localhost:3307/mydb?useSSL=false&serverTimezone=UTC at com.zaxxer.hikari.util.DriverDataSource.(DriverDataSource.java:110) ~[HikariCP-5.0.1.jar:na] at

2023-04-06T01:34:30.657-03:00 INFO 5576 --- [ restartedMain] SQL dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect 2023-04-06T01:34:30.659-03:00 WARN 5576 --- [ restartedMain] org.hibernate.orm.deprecation
: HHH90000026: MySQL8Dialect has been deprecated; use org.hibernate.dialect.MySQLDialect instead

2023-04-06T01:34:31.425-03:00 INFO 5576 --- [ restartedMain] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting...

2023-04-06T01:34:31.439-03:00 ERROR 5576 --- [ restartedMain] j.LocalContainerEntityManagerFactoryBean : Failed to initialize JPA EntityManagerFactory: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.RuntimeException: Driver org.h2.Driver claims to not accept jdbcUrl, jdbc=mysql://localhost:3307/mydb?useSSL=false&serverTimezone=UTC

2023-04-06T01:34:31.440-03:00 WARN 5576 --- [ restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.RuntimeException: Driver org.h2.Driver claims to not accept jdbcUrl, jdbc=mysql://localhost:3307/mydb?useSSL=false&serverTimezone=UTC

2023-04-06T01:34:31.442-03:00 INFO 5576 --- [ restartedMain] o.apache.catalina.core.StandardService : Stopping service [Tomcat]

2023-04-06T01:34:31.453-03:00 INFO 5576 --- [ restartedMain] .s.b.a.l.ConditionEvaluationReportLogger :

Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.

2023-04-06T01:34:31.471-03:00 ERROR 5576 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is java.lang.RuntimeException: Driver org.h2.Driver claims to not accept jdbcUrl, jdbc=mysql://localhost:3307/mydb?useSSL=false&serverTimezone=UTC

Caused by: java.lang.RuntimeException: Driver org.h2.Driver claims to not accept jdbcUrl, jdbc=mysql://localhost:3307/mydb?useSSL=false&serverTimezone=UTC

------------------------------------------------------------------------ BUILD SUCCESS ------------------------------------------------------------------------ Total time: 6.437 s Finished at: 2023-04-06T01:34:31-03:00

6
  • Tienes el @entity en la entidad?la query del repositorio prueba a comentarla a ver si es que esta mal. y asi sin ver el reto del proyecto no se me ocurre mas
    – unknow
    el 19 mar. a las 9:05
  • hola ya subilas imagenes del codigo, las @Entity estan todas no parecen ser el problema
    – WWWilliam
    el 19 mar. a las 16:41
  • no le veo nada raro. el@repository ya no es necesario en las ultimas versiones de spring
    – unknow
    el 19 mar. a las 18:07
  • Hola wwwwww, bienvenido, la pregunta debe ser autocontenida, esto es que no dependa de imágenes o enlaces, por favor, edita tu pregunta elimina las imágenes, y agrega tu código y mensajes de error como texto, así evitarás recibir votos negativos y lograrás que tu pregunta sea mejor recibida, gracias. el 19 mar. a las 19:44
  • gracias marce, ahora lo corrijo
    – WWWilliam
    el 19 mar. a las 20:55

1 respuesta 1

0

Es error cuando no. Define correctamente el datasource , puede ser falta librería de spring-jpa o spring-jdbc, y el correspondiente driver. Por otro lado el application.properies/yaml puede definido el driver

El problema es este mismo https://stackoverflow.com/questions/57247240/spring-boot-jpa-mysql-failed-to-determine-a-suitable-driver-class , pero en post citado falta configurar la ubicación del server

Por último también dentro de las respuesta se cita como crear el Bean datasource

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.