Spring Boot DataSource Configuration
DataSource configuration is provided by configuration properties entries ( spring.datasource.* ) in application.properties file.
The properties configuration decouples the configuration from the application code. This way, we can import the datasource configurations from even configuration provider systems.
Below given configuration shows sample properties for H2, MySQL, Oracle and SQL Server databases.
application.properties
# H2 DB
spring.datasource.url=jdbc:h2:file:C:/temp/testDB
spring.datasource.username=sa
spring.datasource.password=blank
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
# MySQL
spring.datasource.url=jdbc:mysql://localhost:3306/testDB
spring.datasource.username=dbuser1
spring.datasource.password=dbpass1
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.database-platform=org.hibernate.dialect.MySQL5InnoDBDialect
# Oracle
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:testDB
spring.datasource.username=dbuser1
spring.datasource.password=dbpass1
spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
# SQL Server
spring.datasource.url=jdbc:sqlserver://localhost;databaseName=testDB
spring.datasource.username=dbuser1
spring.datasource.password=dbpass1
spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.jpa.hibernate.dialect=org.hibernate.dialect.SQLServer2012Dialect
Recent Comments