티스토리 뷰
1. auto configuration은 스프링 부트가 만들어진 중요한 이유 중 하나이다.
1-1 스프링의 설정은 Dependency Injection과 IOC 때문에 코드만큼 늘어날 수 밖에 없는 구조를 가지고 있다.
1-2 예전에는 코드에서 수행했던 모든 의존성에 대한 처리를 프레임워크에서 수행해야 하므로
1-2-1 언제, 어디에. 어떻게 의존성을 주입해야 할지에 대해 모든 기술이 별도로 이루어져야 한다.
1-2-2 이것이 POJO를 가능하게 한 스프링의 장점이지만 반대로 너무 많은 설정은 단점이 될 수 밖에 없다.
1-3 이것을 해결하기 위한 시도로 스프링 부트가 제안되었고, 프레임워크 개발자들이 제안하는 권고를 담고 있다.
1-3-1 즉 많이 사용되는 설정과 인과 관계가 있는 것은 프레임워크에서 자동으로 설정해 주도록 한 것이다.
2. 스프링에 대한 자동설정은 application.properties에서 수많은 설정값을 통해 제어가능하지만
2-1 어떻게 이런 제어값들이 반영되는지는 코드를 통해 알 수 있다.
2-2 스프링에는 spring-boot-autoconfigure 로 시작하는 패키지가 있는데 안에 수많은 클래스를 담고 있다.
2-3 org.springframework.boot.autoconfigure.jdbc 패키지의 DataSourceAutoConfiguration 클래스 일부이다.
2-3-1 @ConditionalOnClass는 같이 클래스가 classpath에 있는 것을 체크하여 등록하거나
2-3-2 prefix가 spring.datasource로 지정된 property가 설정파일에 지정여부를 체크해서 설정하게 된다.
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ DataSource.class, EmbeddedDatabaseType.class })
@ConditionalOnMissingBean(type = "io.r2dbc.spi.ConnectionFactory")
@EnableConfigurationProperties(DataSourceProperties.class)
@Import({ DataSourcePoolMetadataProvidersConfiguration.class, DataSourceInitializationConfiguration.class })
public class DataSourceAutoConfiguration {
@Configuration(proxyBeanMethods = false)
@Conditional(EmbeddedDatabaseCondition.class)
@ConditionalOnMissingBean({ DataSource.class, XADataSource.class })
@Import(EmbeddedDataSourceConfiguration.class)
protected static class EmbeddedDatabaseConfiguration {
}
@Configuration(proxyBeanMethods = false)
@Conditional(PooledDataSourceCondition.class)
@ConditionalOnMissingBean({ DataSource.class, XADataSource.class })
@Import({ DataSourceConfiguration.Hikari.class, DataSourceConfiguration.Tomcat.class,
DataSourceConfiguration.Dbcp2.class, DataSourceConfiguration.Generic.class,
DataSourceJmxConfiguration.class })
protected static class PooledDataSourceConfiguration {
}
/**
* {@link AnyNestedCondition} that checks that either {@code spring.datasource.type}
* is set or {@link PooledDataSourceAvailableCondition} applies.
*/
static class PooledDataSourceCondition extends AnyNestedCondition {
PooledDataSourceCondition() {
super(ConfigurationPhase.PARSE_CONFIGURATION);
}
@ConditionalOnProperty(prefix = "spring.datasource", name = "type")
static class ExplicitType {
}
@Conditional(PooledDataSourceAvailableCondition.class)
static class PooledDataSourceAvailable {
}
}
3. 실행 시에도 이런 자동설정에 대한 내용을 확인 할 수 있는데 command line을 통해 실행할 수 있다.
3-1 spring-boot maven 플러그인이 컴파일 설정이나 include된 라이브러리 등을 기동시 표출해 준다.
3-2 아래는 디버깅 레벨 만 실행시에 설정한 부분이다. property를 추가하고 싶으면 ','로 연결하면 된다.
$ mvn spring-boot:run -Dspring-boot.run.arguments=--logging.level.root=debug
3-3 몰론 application.properties에서도 아래처럼 설정하면 동일하게 자동설정이 출력된다.
logging.level.root=debug
4. Property를 적용하는 우선순위는 아래의 웹페이지를 참고한다.
24. Externalized Configuration
Getters and setters are usually mandatory, since binding is through standard Java Beans property descriptors, just like in Spring MVC. A setter may be omitted in the following cases:Maps, as long as they are initialized, need a getter but not necessarily a
docs.spring.io
1. Devtools global settings properties on your home directory (~/.spring-boot-devtools.properties when devtools is active).
2. @TestPropertySource annotations on your tests.
3. properties attribute on your tests. Available on @SpringBootTest and the test annotations for testing a particular slice of your application.
4. Command line arguments.
5. Properties from SPRING_APPLICATION_JSON (inline JSON embedded in an environment variable or system property).
6. ServletConfig init parameters.
7 ServletContext init parameters.
8 JNDI attributes from java:comp/env.
9 Java System properties (System.getProperties()).
10 OS environment variables.
11 A RandomValuePropertySource that has properties only in random.*.
12 Profile-specific application properties outside of your packaged jar (application-{profile}.properties and YAML variants).
13 Profile-specific application properties packaged inside your jar (application-{profile}.properties and YAML variants).
14 Application properties outside of your packaged jar (application.properties and YAML variants).
15 Application properties packaged inside your jar (application.properties and YAML variants).
16 @PropertySource annotations on your @Configuration classes.
17 Default properties (specified by setting SpringApplication.setDefaultProperties).
'Spring > Spring Boot' 카테고리의 다른 글
Spring Boot : @ResponseStatus, @ExceptionHandler (0) | 2020.08.08 |
---|---|
Spring Boot : 이미지 업로드와 표출 (0) | 2020.08.06 |
Spring Boot : CommandLineRunner (0) | 2020.07.10 |
Spring Boot : WebJars 사용하기 (0) | 2020.07.07 |
Spring Boot : 내장 서버를 톰캣에서 제티로 변경하기 (0) | 2020.05.27 |
- Total
- Today
- Yesterday
- 도커 개발환경 참고
- AWS ARN 구조
- Immuability에 관한 설명
- 자바스크립트 멀티 비동기 함수 호출 참고
- WSDL 참고
- SOAP 컨슈머 참고
- MySql dump 사용법
- AWS Lambda with Addon
- NFC 드라이버 linux 설치
- electron IPC
- mifare classic 강의
- go module 관련 상세한 정보
- C 메모리 찍어보기
- C++ Addon 마이그레이션
- JAX WS Header 관련 stackoverflow
- SOAP Custom Header 설정 참고
- SOAP Custom Header
- SOAP BindingProvider
- dispatcher 사용하여 설정
- vagrant kvm으로 사용하기
- git fork, pull request to the …
- vagrant libvirt bridge network
- python, js의 async, await의 차이
- go JSON struct 생성
- Netflix Kinesis 활용 분석
- docker credential problem
- private subnet에서 outbound IP 확…
- 안드로이드 coroutine
- kotlin with, apply, also 등
- 안드로이드 초기로딩이 안되는 경우
- navigation 데이터 보내기
- 레이스 컨디션 navController
- raylib
- hibernate
- Angular
- 설정
- WebMvc
- 스프링
- XML
- 로그인
- form
- MYSQL
- 외부파일
- 상속
- Spring
- login
- Validation
- one-to-many
- crud
- RestTemplate
- 하이버네이트
- jsp
- Security
- mapping
- 스프링부트
- Rest
- spring boot
- 매핑
- Spring Security
- 자바
- Many-To-Many
- 설정하기
- one-to-one