• Xxx-Spring-Boot-Autoconfigure 모듈: 자동 설정

  • Xxx-Spring-Boot-Starter 모듈: 필요한 의존성 정의

  • 그냥 하나로 만들고 싶을 때는?

    ○ Xxx-Spring-Boot-Starter

  • 구현방법

1. 의존성 추가

<dependencies>
	<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-autoconfigure</artifactId>
    </dependency>
	<dependency>
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-autoconfigure-processor</artifactId> 
      <optional>true</optional>
	</dependency>
</dependencies>

<dependencyManagement>
  <dependencies>
    <dependency> 
      <groupId>org.springframework.boot</groupId> 
      <artifactId>spring-boot-dependencies</artifactId> 
      <version>2.0.3.RELEASE</version> 
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

2. @Configuration 파일 작성

3. src/main/resource/META-INFspring.factories 파일 만들기

4. spring.factories 안에 자동 설정 파일 추가

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 
  me.baekssul.HolomanConfiguration

5. mvn install
  --> 빌드하여 jar 생성, 다른 메이븐 프로젝트에서 사용할 수 있도록 local maven 저장소에 설치

  • @EnableAutoConfiguration (@SpringBootApplication 안에 숨어 있음)
  • 빈은 사실 두 단계로 나눠서 읽힘
    • 1단계: @ComponentScan
    • 2단계: @EnableAutoConfiguration
  • 컴포넌트 스캔은 Component 어노테이션을 가지고 있는 클래스를 스캔하여 Bean으로 등록
  • @ComponentScan
    • @Component
    • @Configuration @Repository @Service @Controller @RestController
  • @EnableAutoConfiguration
    • spring.factories
      • org.springframework.boot.autoconfigure.EnableAutoConfiguration
    • @Configuration
    • @ConditionalOnXxxYyyZzz (조건에 따라 bean을 등록)

의존성은 pom.xml 에서 관리함

 

의존성을 추가해주는 방법은

<dependencies> 아티팩트 내에 <dependency> ... </dependency>를 추가함.

 

스프링부트에서 버전을 관리해주지 않는 의존성의 경우 버전까지 표기해주어야 함.

 

기존 의존성의 버전을 수정해야하는 경우

<properties> 아티팩트를 추가하고 그 안에 <..version>을 표기해서 오버라이딩 해줌.

백기선의 스트링부트 

스프링부트는 스프링 기반의 애플리케이션을 만들 때 빠르고 쉽게 만들어준다.

설정 또한 많이 사용되는 항목을 자동으로 설정해준다.

톰캣 라이브러리 제공

 

프로젝트 생성 후

pom.xml에 spring boot를 부모로 설정

starter-web 의존성 추가

maven-plugin 의존성 추가 

reimport 필요

<!-- Inherit defaults from Spring Boot -->
	<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.3.RELEASE</version>
	</parent>

	<!-- Add typical dependencies for a web application -->
	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-web</artifactId>
		</dependency>
	</dependencies>

	<!-- Package as an executable jar -->
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

java디렉토리 내 패키지 아래 클래스(ex.Application) 만들고

스프링부트 어플리케이션 생성

@SpringBootApplication
public class Application {

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

 

또는 

 

start.spring.io/

 

 

메인 애플리케이션의 위치는 /main/java/기본 패키지에 만들어줌.

+ Recent posts