studying...
  • 노트의목적
  • 웹전반
    • HTTP
      • 1. HTTP
      • 2. HTTP_Client
      • 3. HTTP_Server
      • 4. JAVA_HTTP_Server
      • 5. Spring_Web_MVC
    • REST_API
      • 1. REST_API
      • 2. URI&MIME_type
      • 3. COLLECTION_Pattern
      • 4. COLLECTION_Pattern_adjustment
      • 5. Spring_Web_MVC
    • DTO_JSON_CORS
      • 1. DTO
      • 2. 직렬화
      • 3. Jackson
      • 4. CORS
    • Layered_Architecture
      • 1. Layered_Architecure
      • 2. Data_Access
      • 3. Domain_Model
    • DI&Spring_Test
      • 1. Dependency_Injection
      • 2. Unit_Test
      • 3. Spring_Test
      • 4. TDD
    • Database
      • 1. Database
      • 2. Relational_Model
      • 3. JDBC
    • JPA
      • 1. ORM
      • 2. Hibernate
      • 3. Embeddable
      • 4. Relationship Mapping
      • 5. Spring Data JPA
    • 도메인_주도_설계
      • 1. DDD
      • 2. Strategic Design
      • 3. Entity, Value Object
      • 4. Aggregate
      • 5. Repository
    • Hexagonal_Architecture
      • 1. SOLID
      • 2. Hexagonal_Architecture
      • 3. 도메인 주도 설계 핵심
    • Spring_Security
      • 1. 애플리케이션 보안
      • 2. 인증
      • 3. 로그인 & 로그아웃
      • 4. 회원가입
      • 5. JWT&Authority
    • File_Upload
      • 1. Multipart_FormData
      • 2. Separation_of_Concerns
      • 3. Cloudinary
    • CQRS
      • 1. CQRS
      • 2. Redis
  • 면접대비
  • book
    • RealMySQL8.0
      • 4장
      • 5장
      • 8장
      • 9장
    • Object
      • 1장
      • 2장
      • 3장
      • 4장
      • 5장
      • 6장
      • 7장
      • 8장
      • 9장
    • ModernJava
      • ch1
      • ch2
    • 클라우드네이티브를위한 쿠버네티스 실전 프로젝트
      • 1장
      • 2장
      • 3장
      • 4장
    • 테라폼 쿡북
      • 2장
      • 3장
      • 4장
      • 5장
      • 6장
  • lecture
    • 외워서끝내는네트워크기초
    • 외워서끝내는네트워크심화
    • aws
      • Architecting_on_AWS
      • Architecrting-advanced
      • Developing_on_AWS
      • migration_essentials
      • Resilience
      • Running_Containers_on_EKS
    • Ansible
    • k8s
      • section2
      • section3
    • Terraform
  • experiences
    • workshops
      • EKS
Powered by GitBook
On this page
  1. 웹전반
  2. File_Upload

3. Cloudinary

Previous2. Separation_of_ConcernsNextCQRS

Last updated 1 year ago

환경변수(환경변수를 다루는 법)

  1. application.yml파일에서 환경변수

JAVA_HOME, OS변수등을 application.properties 파일에서 하용하려면

java.home=${JAVA_HOME}

environment.name=${OS}

baeldung.presentation=${HELLO_BAELDUNG}. Java is installed in the folder: ${JAVA_HOME}

이렇게 사용하면 된다.

코드상에서 사용하는 방법은

  1. @Value 어노테이션 사용

@Value("${baeldung.presentation}")
private String baeldungPresentation;
  1. 스프링의 Environment 객체 사용

@Autowired
private Environment environment;

environment.getProperty("baeldung.presentation")
  1. Properties를 @ConfigurationProperties로 그룹화

환경변수에 baeldung으로 시작하는 환경변수들이 존재할 때 이런 식으로 컴포넌트화 해서 환경변수를 객체로 전환하고

@Component
@ConfigurationProperties(prefix = "baeldung")
public class BaeldungProperties {

    private String presentation;

    public String getPresentation() {
        return presentation;
    }

    public void setPresentation(String presentation) {
        this.presentation = presentation;
    }
}
@Autowired
private BaeldungProperties baeldungProperties;

해당 객체를 주입받아

baeldungProperties.getPresentation()

프로퍼티를 얻을 수 있다.

환경변수(환경변수를 다루는 법)