I have seen if we declare below three properties in the application. properties in spring boot , we are able to connect the oracle database through spring data jpa
spring.datasource.url= jdbc:oracle:thin:@localhost:1521:orcl
spring.datasource.username=SYS as SYS DBA
spring.datasource.password=root
My Question is why we are not providing driver name here. IS this something that It is automatically mapped the driver name here?
from documentation Connection to a Production Database
You often do not need to specify the driver-class-name, since Spring Boot can deduce it for most databases from the url
This @EnableAutoConfiguration
annotation does the magic..Spring boot scans the pom.xml
and build your project based on dependency added. So if you add oracle dependency then it will configure oracle driver for you.
Spring can infer from spring.datasource.url
about which driver should be used.
Spring document says that :
You often do not need to specify the driver-class-name, since Spring Boot can deduce it for most databases from the url.
For a pooling DataSource to be created, we need to be able to verify that a valid Driver class is available, so we check for that before doing anything. In other words, if you set spring.datasource.driver-class-name=com.mysql.jdbc.Driver, then that class has to be loadable.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.