What settings are required to make spring boot generate tables automatically?

Asked

Viewed 1,770 times

0

I am currently trying to configure my application with spring-boot to generate tables automatically but still do not know how, someone can help?

  • I think your question should be more specific. I recommend this tutorial here: https://spring.io/guides/gs/accessing-data-mysql/

1 answer

1

You must create the file application.properties and configure your database on it. Example:

spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.url=jdbc\:mysql\://localhost/meu-banco
spring.jpa.hibernate.ddl-auto=update

When the parameter spring.jpa.hibernate.ddl-auto is configured as update, When starting the application, Hibernate will check that tables have already been created, if they have not yet been created, it will automatically create them.

Another detail, is that to create the tables, their entities should be annotated with @Entity

Browser other questions tagged

You are not signed in. Login or sign up in order to post.