4
votes

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).

1
Can't help much without source code... Also please try to provide a MCVEsɐunıɔןɐqɐp
what is your spring:profiles:active property value in yml?amant singh
spring: profiles: active: "dev" main: banner-mode: "off" ---user10164097
do you have a space after colon for driver-class-name:oracle.jdbc.driver.OracleDriver ? If not that is wrong. You need to have a space after colon according to yml conventionpvpkiran
there is no space@pvpkiranuser10164097

1 Answers

1
votes

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