.properties 파일 생성

spring.datasource.url=
spring.datasource.username=
spring.datasource.password=
spring.datasource.driver-class-name=

test_test=불러와랑

<application-db-dev.properties> 파일

위와 같은 폴도구조로 .properties 파일을 생성해주자. 경로, 위치는 아무런 상관이 없지만 불러올수있는 위치에 생성해야한다. 여러가지를 고려해서 resources에 하위 디렉토리를 만들고 생성하거나 resources에 바로 생성하여 classpath를 이용하는것을 권장한다.

.properties AutoConfiguration

@SpringBootApplication
@PropertySource("classpath:application-db-dev.properties")
public class DashboardApplication {

    public static void main(String[] args) {
        SpringApplication.run(DashboardApplication.class, args);
    }
}

<DashboardApplication.java> 파일

spring runner class에 @PropertySource 를 명시해서 해당 properties 파일이 메모리상에 올라가도록 해주자. 올라간 properties 파일은 spring-boot-auto-configuration 을 통해 config에 필요한 데이터는 자동으로 injection 된다. 위에 예시로는 spring-datasource가 자동으로 입력된다.

.properties calling Value

/// 1번
@Componenet
public class test{

	@value($"{test_test}")
	public String test;
}

/// 2번
@Componenet
@PropertySource("classpath:application-db-dev.properties")
public class test{

	@value($"{test_test}")
	public String test;
}

<test.java> 파일

.properties 파일의 Spring data만 뺴오고 싶은경우 위에 두가지 방법중 하나를 선택해주면된다.

1번의 경우 메모리에 해당 .properties 파일이 올라와 있을경우 @Value 로 바로 찾아 올수 있지만, 메모리상에 .properties 파일이 올라와 있지 않을경우 2번과 깉이 해주면 된다 .. !