Spring Boot ORM - Application.properties

Spring boot 从 application.properties 读取应用程序以及持久性相关的属性。 在这里,我们也可以配置休眠或任何其他 ORM 框架特定的属性。我们使用通用属性,以便我们可以在 ORM 之间切换而无需更改太多代码。 默认情况下,如果 POM.xml 中没有指定其他 ORM 库,spring boot 会将 hibernate 配置为 ORM 提供程序。

src −> main −> resources 目录下创建 application.properties 并更新如下图。

application.properties


#datasource configurations
spring.datasource.url=jdbc:mysql://localhost:3306/tutorialspoint?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
spring.datasource.password=root@123
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
# show SQL
spring.jpa.show-sql: true
# DDL generation
spring.jpa.generate-ddl=true

以下是 application.properties 的关键属性的描述。

  • spring.datasource − 数据库特定属性,如连接 url、用户名、密码、驱动程序类等。

  • spring.jpa − jpa 特定属性,例如显示 sql、允许创建表等。