SpringBoot9AM 17122020
SpringBoot9AM 17122020
----Note----------------------------------------------------------
*) Level in Key = Symbol dot(.) in keys creates a new/next level
ex: my.app.code=A
Her my - 1st level in key, app-2nd level in key, code-3rd level in key
--application.yml---
spring:
datasource:
driver-class-name: OracleDriver
url: jdbc:oracle
username: system
password: abc
----------------------------------
__.properties
my.app.id=10
my.app.code=A
__.yml
my:app:id:10
my:app:code:A
__.yml
my:
app:
id:10
code:A
3. Before every new level(not 1st level) provide spaces (at least one)
[Space count must match for same level]
__.yml
my:
app:
id:10
code:A
4. Finally for value, give exactly one space ( between last level and data)
========Examples================================
Ex#1.
--application.properties---
my.app.code=A
my.app.model=B
my.grade.service=new
my.grade.cost=600
---application.yml----
my:
app:
code: A
model: B
grade:
service: new
cost: 600
---------------------
Ex#2
--application.properties---
spring.jpa.show-sql=true
spring.jpa.ddl-auto=create
spring.hikari.size=20
spring.hikari.name=hrk
---application.yml---
spring:
jpa:
show-sql: true
ddl-auto: create
hikari:
size: 20
name: hrk
---------------------
Ex#3
---application.properties---
spring.jpa.hibernate.auto-create=true
spring.jpa.show-sql=true
spring.jpa.hibernate.format.export=new
spring.jpa.model=entity
spring.jpa.grade.code=accept
---application.yml----
spring:
jpa:
hibernate:
auto-create: true
format:
export: new
show-sql: true
model: entity
grade:
code: accept
---------------------------------
Ex#4
---application.proprties---
my.grade.mode=A
spring.format.text=one
my.accept.mode=new
spring.jpa.show=true
my.grade.state=SA
spring.format.active=true
spring.jpa.final=mode
---application.yml----
my:
grade:
mode: A
state: SA
accept:
mode: new
spring:
format:
text: one
active: true
jpa:
show: true
final: mode
org.yaml.snakeyaml.scanner.ScannerException:
mapping values are not allowed here
----------code---------------------------------
#1 Create Spring Boot Starter Project
Name : SpringBoot2YamlExp
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
@Component
public class DataReadRunner implements CommandLineRunner {
@Value("${my.app.id}")
private Integer pid;
@Value("${my.app.name}")
private String pname;
@Value("${my.app.cost}")
private Double pcost;
}
--------------------------------------------------------------