> For the complete documentation index, see [llms.txt](https://blakes-organization.gitbook.io/rainsister/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blakes-organization.gitbook.io/rainsister/spring/spring-boot-configuration-processor.md).

# spring-boot-configuration-processor  는 뭐하는놈임?

현재 springboot은 기본으로 .yml 을 우선시한다. 하지만 가끔씩 아날로그식? .properties 구석 과 xml 구성으로 값을 가져와 써야 할때가 종종 있다.&#x20;

그럼 어떻게 사용할까?

poml.xm 추가&#x20;

```xml
<dependency>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-configuration-processor</artifactId>
     <optional>true</optional>
 </dependency>
```

application.properties

```properties
author.name=samsung
author.age=20
```

설정클래스 상단에 @PropertySource("classpath:your.properties")을 사용하면 yml 구성을 로딩한것과 같은 효과다.

```java
@Component
@PropertySource(value = {"classpath:static/config/authorSetting.properties"},
        ignoreResourceNotFound = false, encoding = "UTF-8", name = "authorSetting.properties")
public class AuthorTest {
 
    @Value("${author.name}")
    private String name;
    @Value("${author.age}")
    private int age;
}
```

@PropertySource 의 속성 요약\
1.value：설정파일 경로.\
2.ignoreResourceNotFound：지정파일 존재하지 않을시 에러! 기본옵션 false 이다.true 설정해야 파일 없으면 오류. 실제 개발시 ignoreResourceNotFound 를 false로 설정한다.\
3.encoding：파일 읽어드릴시 UTF-8 인코딩.

@Value 사용이 좀 많을때 등장한것이 바로 @ConfigurationProperties 옵션이다.

```java
@Component
@ConfigurationProperties(prefix = "author")
@PropertySource(value = {"classpath:static/config/authorSetting.properties"},
        ignoreResourceNotFound = false, encoding = "UTF-8", name = "authorSetting.properties")
public class AuthorTest {
 
    private String name;
    private int age;
 
}
```

```java
@RestController
@EnableConfigurationProperties
public class DemoController {
 
    @Autowired
    AuthorTest authorTest;
 
    @RequestMapping("/")
    public String index(){
        return "author's name is " + authorTest.getName() + ",ahtuor's age is " + authorTest.getAge();
    }
}
```

마지막으로&#x20;

@ConfigurationProperties 사용하기위 위해서는 꼭 @EnableConfigurationProperties 를 써서 활성화 한다.

끝!
