Spring Boot DataSource Autoconfiguration: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Spring Boot Concepts - DataSource Autoconfiguration")
 
No edit summary
Line 2: Line 2:


* [[Spring_Boot_Concepts#DataSource_Autoconfiguration|Spring Boot Concepts - DataSource Autoconfiguration]]
* [[Spring_Boot_Concepts#DataSource_Autoconfiguration|Spring Boot Concepts - DataSource Autoconfiguration]]
=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=
<syntaxhighlight lang='yaml'>
spring:
  datasource:
    url: jdbc:mysql://localhost/mydatabase
    username: someuser
    password: somepasswd
</syntaxhighlight>
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:
<syntaxhighlight lang='yaml'>
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
</syntaxhighlight>

Revision as of 20:55, 3 December 2018

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