senthil G
senthil G

Reputation: 1

Spring Boot- Profile setting Through YML file is not working

In Spring Boot program, profile setting using application.yml is not working whereas the same program is working using applicaiton.properties. the following actions has been performed but it ended up in vain

  1. In Eclipse ide Project-Clean has been done
  2. Maven project updated
  3. Spaces in YML file removed and corrected
  4. YML file is deleted and recreated.

applicaiton.yml

spring:
  profiles: 
    active: dev

applicaiton-dev.yml

spring: 
 datasource:
   driver-class-name: com.mysql.cj.jdbc.Driver
   url: jdbc:mysql:///ntspbms616db
   username: root
   password: root
   dbcp2:
   max-total: 100
   initial-size: 10
   max-conn-lifetime-millis: 10000000
   type:  org.apache.commons.dbcp2.BasicDataSource

The error i got after running the program is

Enter the Employee Name 
Raja
Enter the Employee  Designation
Manager
Enter the Basic Salary
9898999
12:28:40.622 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
org.yaml.snakeyaml.scanner.ScannerException: while scanning for the next token
found character '\t(TAB)' that cannot start any token. (Do not use \t(TAB) for indentation)
 in 'reader', line 4, column 2:

How to resolve the issue?

Upvotes: 0

Views: 845

Answers (1)

kerbermeister
kerbermeister

Reputation: 4231

This error means literally what is says.

The "tab" is not permitted by the YAML specs:

To maintain portability, tab characters must not be used in indentation, since different systems treat tabs differently. Note that most modern editors may be configured so that pressing the tab key results in the insertion of an appropriate number of spaces.

So, you should double check for the tab characters in your yaml files and if exist, replace them by double space.

Also, just to add, I can see incorrect formatting of dbcp2 section, without any intendation, so, it should look like this:

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql:///ntspbms616db
    username: root
    password: root
    dbcp2:
      max-total: 100
      initial-size: 10
      max-conn-lifetime-millis: 10000000
    type: org.apache.commons.dbcp2.BasicDataSource

Upvotes: 1

Related Questions