Spring Boot YAML Auto Data Source Configuration Issue - Data Source URL not picked up

user10164097 :

Currently, We are creating a spring boot project for our newer modules.

Technology We have used as follows :

  1. Java 1.8
  2. Maven 3.5.2
  3. Spring Boot: 1.5.6.RELEASE (spring-boot-starter-parent)

public class Application {

public static void main(String[] args) {
    SpringApplication.run(Application.class, args);
}

@Autowired
private DataSource datasource;

}

application.properties

  • spring.datasource.url=jdbc:oracle:XXX:@XXX:XXX/XXX
  • spring.datasource.username=XXX
  • spring.datasource.password=XXX
  • spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver

application.yml

  • spring:

    • profiles:
    • active: "dev"
    • main:

      - banner-mode: "off"

  • spring:

    • profiles: dev
    • datasource:
      • url:jdbc:oracle:XXX:@XXX:XXX/XXX
      • username:XXX
      • password:XXX
      • driver-class-name:oracle.jdbc.driver.OracleDriver

When we are adding data source information as properties file the application working as expected. But information as YAML means showing below error.

ERROR

Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'testapplication': Unsatisfied dependency expressed through field 'datasource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Tomcat.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.tomcat.jdbc.pool.DataSource]: Factory method 'dataSource' threw exception; nested exception is org.springframework.boot.autoconfigure.jdbc.DataSourceProperties$DataSourceBeanCreationException: Cannot determine embedded database driver class for database type NONE. If you want an embedded database please put a supported one on the classpath. If you have database settings to be loaded from a particular profile you may need to active it (the profiles "dev" are currently active).

pvpkiran :

Yml standards dictate us to specify a space after colon(:). Please have a look at the documentation Change your yml like this and It should work fine.

spring:
  profiles: dev
  datasource:
     url: jdbc:oracle:XXX:@XXX:XXX/XXX
     username: XXX
     password: XXX
     driver-class-name: oracle.jdbc.driver.OracleDriver

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=108692&siteId=1