Solucionado (ver solução)
Solucionado
(ver solução)
6
respostas

Conexão com MYSQL encerra

Ao subir o spring, configurando para usar um banco MYSQL a conexão sobe e logo em seguida ela encerra. Isso já aconteceu com alguém aqui ?

Closing JPA EntityManagerFactory for persistence unit 'default'


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.4.3)

2021-03-01 10:00:57.971  INFO 10432 --- [           main] b.c.f.spring.data.SpringDataApplication  : Starting SpringDataApplication using Java 1.8.0_171 on Felipe-PC with PID 10432 (C:\Users\Felipe\eclipse-workspace\spring-data\target\classes started by Felipe in C:\Users\Felipe\eclipse-workspace\spring-data)
2021-03-01 10:00:57.974  INFO 10432 --- [           main] b.c.f.spring.data.SpringDataApplication  : No active profile set, falling back to default profiles: default
2021-03-01 10:00:58.527  INFO 10432 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2021-03-01 10:00:58.545  INFO 10432 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 8 ms. Found 0 JPA repository interfaces.
2021-03-01 10:00:59.162  INFO 10432 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2021-03-01 10:00:59.232  INFO 10432 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.4.28.Final
2021-03-01 10:00:59.414  INFO 10432 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
2021-03-01 10:01:00.162  INFO 10432 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-03-01 10:01:01.172  INFO 10432 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-03-01 10:01:01.192  INFO 10432 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2021-03-01 10:01:02.026  INFO 10432 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2021-03-01 10:01:02.037  INFO 10432 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2021-03-01 10:01:02.171  INFO 10432 --- [           main] b.c.f.spring.data.SpringDataApplication  : Started SpringDataApplication in 4.695 seconds (JVM running for 5.306)
2021-03-01 10:01:02.181  INFO 10432 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2021-03-01 10:01:02.185  INFO 10432 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2021-03-01 10:01:02.200  INFO 10432 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
6 respostas

application.properties:

spring.datasource.url=jdbc:mysql://${MYSQL_HOST:localhost}:3306/enterprise

spring.datasource.username=root spring.datasource.password=admin

spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.jpa.show-sql=false spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5Dialect

Oi Felipe

Já tive esse problema quando configurei o MySQL5Dialect para acessar o MySQL8 instalado localmente na minha máquina, confirma se você não está tendo esse problema também, nesse caso teria que atualizar o dialect para o MySQL8 ou então instalar o Mysql5

solução!

Confere se tu tens a dependência Spring Boot Starter Web, no pom.xml. Eu estava com o mesmo problema, baixei a dependência do JPA e do MySQL Connector, e me esqueci da Starter Web. Após atualizar o pom.xml, funcionou perfeitamente.

eu também não estou conseguindo, tentei dezenas de formas diferentes. Meu mySQL 8.0.23, a dependência do pom: mysql mysql-connector-java 8.0.23

o application.properties:

spring.datasource.url=jdbc:mysql://localhost:3306/alura_spring_data spring.datasource.username=root spring.datasource.password=admin

spring.jpa.hibernate.ddl-auto=update spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect spring.jpa.show-sql=false

console:

:: Spring Boot :: (v2.3.9.RELEASE)

2021-03-11 11:11:02.781 INFO 11020 --- [ main] b.c.a.spring.data.SpringDataApplication : Starting SpringDataApplication on DESKTOP-M8M3CI5 with PID 11020 (C:\Users\fbmac\workspace-alura\spring-data\target\classes started by fbmac in C:\Users\fbmac\workspace-alura\spring-data) 2021-03-11 11:11:02.791 INFO 11020 --- [ main] b.c.a.spring.data.SpringDataApplication : No active profile set, falling back to default profiles: default 2021-03-11 11:11:04.029 INFO 11020 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode. 2021-03-11 11:11:04.081 INFO 11020 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 30ms. Found 0 JPA repository interfaces. 2021-03-11 11:11:05.356 INFO 11020 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default] 2021-03-11 11:11:05.515 INFO 11020 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.28.Final 2021-03-11 11:11:06.150 INFO 11020 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.2.Final} 2021-03-11 11:11:06.761 INFO 11020 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Starting... 2021-03-11 11:11:08.457 INFO 11020 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Start completed. 2021-03-11 11:11:08.511 INFO 11020 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect 2021-03-11 11:11:09.516 INFO 11020 --- [ main] o.h.e.t.j.p.i.JtaPlatformInitiator : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform] 2021-03-11 11:11:09.539 INFO 11020 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default' 2021-03-11 11:11:09.870 INFO 11020 --- [ main] b.c.a.spring.data.SpringDataApplication : Started SpringDataApplication in 8.035 seconds (JVM running for 9.343) 2021-03-11 11:11:09.919 INFO 11020 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default' 2021-03-11 11:11:09.930 INFO 11020 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated... 2021-03-11 11:11:10.012 INFO 11020 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.

Ian Michael

Coloca essa dependência aqui que vai funcionar:

org.springframework.boot spring-boot-starter-data-jpa

Também estou tendo o mesmo problema, só é solucionado quando insiro a dependência spring-boot-starter-web. Porém agora fiquei sem entender o porque no vídeo funciona sem essa dependência e o meu só com ela. Seria algo mais natural que realmente, como estou fazendo uma aplicação apenas para acessar o banco não fosse necessário essa dependência web. Mas com essa versão do spring boot não rola, só tá ficando no ar com ela.