
링크
https://spring.io/guides/gs/consuming-rest
Getting Started | Consuming a RESTful Web Service
You can run the application from the command line with Gradle or Maven. You can also build a single executable JAR file that contains all the necessary dependencies, classes, and resources and run that. Building an executable jar makes it easy to ship, ver
spring.io
@JsonIgnoreProperties(ignoreUnknown = Boolean)
- Jackson JSON processing library to indicate that any properties not bound in this type should be ignored
- 해당 어노테이션이 붙은 클래스 혹은 Record의 형식에 맞지 않는다면, Json으로 형식을 변환해주지 않는다.
RestTemplate
- application의 REST 통신을 위해 RestTemplate Bean을 등록해주어야 한다.
- Jackson JSON processing library를 활용해 incoming data를 활용하기 위해서!
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) {
return builder.build();
}
CommandLineRunner
- SpringApplication.run()이 호출된 직후에 실행된다.
- 애플리케이션의 초기화, 데이터베이스 초기화, 외부 서비스와의 연결, 스케쥴러 등의 작업을 수행할 수 있다.
@Bean
@Profile("!test")
public CommandLineRunner run(RestTemplate restTemplate) throws Exception {
return args -> {
// args 는 application 실행 명령에 전달된 인자임
}
}
@Profile
example) @Profile("!test")
- 예시의 경우 해당 빈이 test 프로파일이 아닌 경우에만 등록되어야 함
- application.setAdditionalProfiles()로 수동 등록한 경우, 커스텀 프로파일 파일이 등록된다.
application.setAdditionalProfiles("dev");
application.yml or application.properties 로 인식, default임
application.setAdditionalProfiles("ariana");
application-ariana.yml or application-ariana.properties 로 등록함
'Backend > Spring' 카테고리의 다른 글
gradle - jar 빌드 및 실행 (0) | 2024.02.01 |
---|