Spring Boot DataSource Autoconfiguration

From NovaOrdis Knowledge Base
Revision as of 20:55, 3 December 2018 by Ovidiu (talk | contribs)
Jump to navigation Jump to search

Internal

Overview

DataSource beans can be explicitly configured, but that is usually unnecessary. It is simpler to use Spring Boot autoconfiguration facilities and just provide the URL for the database and credentials.

Configuration

spring:
  datasource:
    url: jdbc:mysql://localhost/mydatabase
    username: someuser
    password: somepasswd

This implies that the appropriate driver is added to the build. If that is done, it is usually unnecessary to specify the JDBC driver class. Spring Boot can figure it out from the structure of the database URL.

If there is a problem, it can be set with:

spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver