* BAEL-4106
application.yml vs application.properties for Spring Boot

* Update README.md
This commit is contained in:
Ricardo Caldas 2020-08-22 05:45:22 -03:00 committed by GitHub
parent 0c657fdd79
commit 16ae922c36
7 changed files with 95 additions and 3 deletions

View File

@ -1,3 +1,9 @@
## Spring Boot Properties
### Relevant Articles:
- [How to Define a Map in YAML for a POJO?](https://www.baeldung.com/yaml-map-pojo)

View File

@ -17,13 +17,11 @@
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
@ -50,5 +48,4 @@
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,27 @@
package com.baeldung.propertiesvsyaml;
import org.springframework.boot.context.properties.ConfigurationProperties;
@ConfigurationProperties(prefix = "app")
public class ConfigProperties {
String name;
String description;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

View File

@ -0,0 +1,16 @@
package com.baeldung.propertiesvsyaml;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;
@Component
public class EnvironmentProperties {
@Autowired
private Environment env;
public String getSomeKey() {
return env.getProperty("key.something");
}
}

View File

@ -0,0 +1,13 @@
package com.baeldung.propertiesvsyaml;
import org.springframework.beans.factory.annotation.Value;
public class ValueProperties {
@Value("${key.something}")
private String injectedProperty;
public String getAppName() {
return injectedProperty;
}
}

View File

@ -0,0 +1,11 @@
application.servers[0].ip=127.0.0.1
application.servers[0].path=/path1
application.servers[1].ip=127.0.0.2
application.servers[1].path=/path2
application.servers[2].ip=127.0.0.3
application.servers[2].path=/path3
spring.datasource.url=jdbc:h2:dev
spring.datasource.username=SA
spring.datasource.password=password
app.name=MyApp
app.description=${app.name} is a Spring Boot application

View File

@ -1,3 +1,25 @@
logging:
file:
name: myapplication.log
spring:
datasource:
password: 'password'
url: jdbc:h2:dev
username: SA
---
spring:
datasource:
password: 'password'
url: jdbc:mysql://localhost:3306/db_production
username: user
application:
servers:
- ip: '127.0.0.1'
path: '/path1'
- ip: '127.0.0.2'
path: '/path2'
- ip: '127.0.0.3'
path: '/path3'
t-shirt-size:
simple-mapping:
XS: 6