SW/Spring Boot

Spring Boot : 스프링 부트 스타터 웹 개념, 예제, 설명

얇은생각 2023. 3. 14. 07:30
반응형

Spring Boot : 스프링 부트 스타터 웹 개념, 예제, 설명

 

 

spring-boot-starter-web에는 두 가지 중요한 기능이 있습니다.

 

웹 개발을 위해 호환됩니다.

자동 구성입니다.

 

웹 애플리케이션을 개발하려면 pom.xml 파일에 다음과 같은 종속성을 추가해야 합니다.

<dependency>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-web</artifactId>  
<version>2.2.2.RELEASE</version>  
</dependency>

 

 

Starter of Spring 웹은 Spring MVC, REST 및 Tomcat을 기본 내장 서버로 사용합니다. 단일 spring-boot-starter-web 의존성은 웹 개발과 관련된 모든 의존성을 일시적으로 끌어당깁니다. 또한 빌드 종속성 수를 줄입니다. spring-boot-starter-web은 다음과 같이 순차적으로 달라집니다.

 

org.springframework.boot:spring-boot-starter

org.springframework.boot:spring-boot-starter-tomcat

org.springframework.boot:spring-boot-starter-validation

com.fasterxml.jackson.core:jackson-databind

org.springframework:spring-web

org.springframework:spring-webmvc

 

기본적으로 spring-boot-starter-web에는 다음과 같은 Tomcat 서버 종속성이 포함되어 있습니다.

<dependency>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-tomcat</artifactId>  
<version>2.0.0.RELEASE</version>  
<scope>compile</scope>  
</dependency>

 

 

spring-boot-starter-web은 웹 개발에 필요한 다음 사항을 자동으로 구성합니다.

 

발송인 서블릿

오류 페이지

정적 종속성을 관리하기 위한 웹 JAR

포함된 서블릿 컨테이너

 

 

 

Spring Boot 내장 웹 서버

각 스프링 부트 응용 프로그램에는 내장된 서버가 포함되어 있습니다. 임베디드 서버는 배포 가능한 응용 프로그램의 일부로 포함되어 있습니다. 임베디드 서버의 장점은 환경에 서버를 미리 설치할 필요가 없다는 것입니다. Spring Boot의 경우 기본 내장형 서버는 Tomcat입니다. Spring Boot은 다음 두 개의 임베디드 서버도 지원합니다.

 

제티 서버입니다.

언더도우 서버입니다.

 

 

 

내장된 다른 웹 서버를 사용

spring-boot-starter-web은 spring-boot-starter-tomcat을 포함하여 Tomcat을 포함하지만, 대신 spring-boot-starter-jetty 또는 spring-boot-starter-undow를 사용할 수 있습니다.

반응형 스택 애플리케이션의 경우, 스프링-부트-스타터-웹 플럭스는 스프링-부트-스타터-리액터-넷티를 포함하여 Reactor Netty를 포함하지만, 대신 스프링-부트-스타터-톰캣, 스프링-부트-스타터-제티 또는 스프링-부트-스타터-언더타워를 사용할 수 있습니다.

 

 

제티 서버

Spring Boot은 Jetty Server라는 임베디드 서버도 지원합니다. 정적 및 동적 콘텐츠를 제공할 수 있는 HTTP 서버 및 Servlet 컨테이너입니다. 기계 간 통신이 필요할 때 사용합니다.

애플리케이션에 Jetty 서버를 추가하려면 pom.xml 파일에 spring-boot-starter-jetty 종속성을 추가해야 합니다.

응용 프로그램에서 Jetty 서버를 사용하는 동안 기본 Tomcat 서버가 spring-boot-starter-web에서 제외되었는지 확인하십시오. 서버 간의 충돌을 방지합니다.

<dependency>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-web</artifactId>  
<exclusions>  
<exclusion>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-tomcat</artifactId>  
</exclusion>  
</exclusions>  
</dependency>  
<dependency>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-jetty</artifactId>  
</dependency>

 

 

application.properties 파일을 사용하여 Jetty 서버의 동작을 사용자 정의할 수도 있습니다.

 

 

언더도우 서버

스프링 부트는 Underow라는 또 다른 서버를 제공합니다. Jetty와 같은 내장형 웹 서버이기도 합니다. 자바 언어로 작성되었으며 JBoss가 관리하고 후원합니다. Underow 서버의 주요 장점은 다음과 같습니다.

 

HTTP/2를 지원

HTTP 업그레이드 지원

웹소켓 지원

Servlet 4.0을 지원

유연성

임베드 가능

 

응용 프로그램에서 Underow 서버를 사용하는 동안 기본 Tomcat 서버가 spring-boot-starter-web에서 제외되었는지 확인하십시오. 서버 간의 충돌을 방지합니다.

<dependency>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-web</artifactId>  
<exclusions>  
<exclusion>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-tomcat</artifactId>  
</exclusion>  
</exclusions>  
</dependency>  
<dependency>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-undertow</artifactId>  
</dependency>

 

 

 

application.properties 파일을 사용하여 Underow 서버의 동작을 사용자 정의할 수도 있습니다.

 

 

 

spring-boot-starter-web vs spring-boot-starter-tomcat

spring-boot-starter-web에는 spring-boot-starter-tomcat을 포함하는 spring 웹 종속성이 포함되어 있습니다. spring-boot-starter-web에는 다음이 포함되어 있습니다.

 

spring-boot-starter

jackson

spring-core

spring-mvc

spring-boot-starter-tomcat

 

 

반면 spring-boot-starter-tomcat에는 Tomcat 서버와 관련된 모든 것이 포함되어 있습니다.

 

core

el

logging

websocket

 

 

starter-tomcat에는 다음과 같은 종속성이 있습니다.

<dependency>  
<groupId>org.apache.tomcat.embed</groupId>  
<artifactId>tomcat-embed-core</artifactId>  
<version>8.5.23</version>  
 <scope>compile</scope>  
</dependency>  
<dependency>  
<groupId>org.apache.tomcat.embed</groupId>  
<artifactId>tomcat-embed-el</artifactId>  
<version>8.5.23</version>  
<scope>compile</scope>  
</dependency>  
<dependency>  
<groupId>org.apache.tomcat.embed</groupId>  
<artifactId>tomcat-embed-websocket</artifactId>  
<version>8.5.23</version>  
<scope>compile</scope>  
</dependency>

 

 

내장된 Tomcat 서버를 사용하지 않고도 spring-mvc를 사용할 수 있습니다. 이렇게 하려면 다음 코드와 같이 <exclusion> 태그를 사용하여 Tomcat 서버를 제외해야 합니다.

<dependency>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-web</artifactId>  
<exclusions>  
<exclusion>  
<groupId>org.springframework.boot</groupId>  
<artifactId>spring-boot-starter-tomcat</artifactId>  
</exclusion>  
</exclusions>  
</dependency>

 

반응형