4

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

7
  • Can't help much without source code... Also please try to provide a MCVE Commented Aug 1, 2018 at 7:19
  • what is your spring:profiles:active property value in yml? Commented Aug 1, 2018 at 7:24
  • spring: profiles: active: "dev" main: banner-mode: "off" --- Commented Aug 1, 2018 at 7:31
  • 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 convention Commented Aug 1, 2018 at 7:32
  • there is no space@pvpkiran Commented Aug 1, 2018 at 7:33

1 Answer 1

3

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.