Skip to content

Instantly share code, notes, and snippets.

@namkyu
Last active May 8, 2018 01:06
Show Gist options
  • Save namkyu/6079b7ae95f5da861421f9e0f93a00f7 to your computer and use it in GitHub Desktop.
Save namkyu/6079b7ae95f5da861421f9e0f93a00f7 to your computer and use it in GitHub Desktop.
spring boot #spring_boot

auto configuration

새로운 프로젝트 마다 반복적인 설정을 해결하기 위한 고민에서 시작

설정 클래스는 다 어디 갔을까?

 - mvc, jpa, datasource 설정들
 - EnableAutoConfigurationImportSelector 에서 설정을 등록한다.
  > META-INF/spring.factories 위치에 설정 파일 리스트 읽어온다.
  > 모든 설정 클래스가 로딩이 되나 스프링 컨테이너에는 올라가지 않는다.

@Conditional(PropertiesCondition.class)

스프링4부터 Conditional 사용 가능 (boot도 해당 버전 이후부터 지원)

@ConditionalOnClass, @ConfitionalOnMissingClass, @ConditionalOnProperties

특정 조건에 Bean을 올리겠다라는 것
PropertiesCondition.class 내부를 들여다 보면 matches 메서드가 있다. 해당 메서드 안에서 조건을 개발함.
스프링부트는 @Conditional* 를 통한 Autoconfiguration을 구현
로그를 debug로 바꿔 auto configuration 동작에 대한 상세 로그를 확인하자.

@Conditional 스프링 4.0부터 지원

클래스 존재 여부, 프로포트 존재 여부, 빈 존재 여부 등 다양한 @Conditional을 제공

트랜잭션 처리를 위해서는

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-aop</artifactId>
    <version>1.5.2.RELEASE</version>
</dependency>
'management.security.enabled' to false.
  management:
  security:
    enabled: false
위의 옵션 지정해야 함

cglib 관련

Spring boot 는 기본적으로 transaction 대상의 aop를 동작시킬 프록시를 cglib 프록시를 사용하게 설정 해놨다. 이 뜻은 인터페이스가 있든 없든 상관없이 무조건 cglib를 사용해서 aop를 사용한다.

@ComponentScan

@ComponentScan convention은  @SpringBootApplication 가 선언되어 있는 패키지 및 서브 패키지가 대상이 된다.
스프링 부트 애플리케이션에는 하나의 애플리케이션 컨텍스트가 존재한다.
참고 : Spring cloud 에서는 bootstrap 이 하나의 애플리케이션 컨텍스트이다.

spring.resources.add-mappings=false

static 리소스에 접근하지 못한다.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment