- 빈 연결 (bean wiring) : ex) dataSouce, transaction manager, kafka listener ...
- 속성 주입 (property injection) ex) db host, id, pw , ssl keystore , user custom properties (no hardcoding)
- spring boot 에서는 대부분 자동화 (starter), 수동 설정하여 override 가능
- cli argument
- ServletContext init parameter
- JNDI attribute
- java system properties (System.getProperties())
- OS env param (EXPORT SPRING_ACTIVE_PROFILES=prod)
랜덤한 미사용 포트로 동작한다
micro 서비스 환경 혹은 test 시에 유용하다
logging:
path: /val/logs/
file: TacoCloud.log
level:
root: warn
org:
springframework:
security: debug
...
greeting:
welcome: ${spring.application.name}
taco:
props:
size: 10
prize: 1000
name: 존맛탱타코
@Component
@ConfigurationProperties(prefix="taco.props")
@Getter
public class TacoProps {
private int size;
@Min(value=5, message="must be between 5 and 5000")
@Max(value=5000, message="must be between 5 and 5000")
private long prize;
private String name;
}
...
@Service
public class TacoServiceImpl {
@AutoWired
private TacoProps tacoProps;
....
}
- 없어도 동작에 이상 없지만, 구성속성 정보를 제공해주므로 개발시 편리하다
- spring-boot-configuration-processor 의존성 추가
ex)src/main/resources/META-INF/additional-spring-configuration-metadata.json
{
properties: [
{
name: "taco.orders.page-size",
type: "int",
description: "user custom properties meta into sample"
}
]
}
logging:
level:
root: warn
---
spring:
profiles: prod
datesource:
url: jdbc:mysql://10.10.20.30/prod-db
---
spring:
profiles: dev
datasource:
url: jdbc:mysql://10.100.200.100/dev-db
java -jar app.jar --spring.profiles,active=prod
or
export SPRING_PROFILES_ACTIVE=prod
@Bean
@Profile("dev")
public DevDataSourceConfiguration {
...
}
@Bean
@Profile("prod")
public ProdDataSourceConfiguration {
...
}
@Bean
@Profile("!prod")
public NotProdDataSourceConfiguration {
...
}