스프링 부트 튜토리얼
Spring Boot 는 RAD ( Rapid Application Development ) 기능을 Spring 프레임 워크에 제공하는 Spring 프레임 워크 모듈입니다 . 그것은 매우 강력하고 완벽하게 작동 하는 스타터 템플릿 기능 에 크게 의존합니다 .
스프링 부트 모듈
1. 스타터 템플릿이란 무엇입니까?
Spring Boot 스타터는 특정 기능을 시작하는 데 필요한 모든 관련 전이 종속성 의 모음 을 포함하는 템플릿입니다 . 예를 들어, Spring WebMVC 애플리케이션을 작성하려면 기존 설정에서 필요한 모든 종속성을 직접 포함해야합니다. 버전 충돌 가능성을 남겨두고 결국 더 많은 런타임 예외가 발생 합니다.
Spring 부트를 사용하면 MVC 응용 프로그램을 만들려면 가져 오기만하면 spring-boot-starter-web됩니다.
pom.xml
<parent> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-parentartifactId> <version>2.1.6.RELEASEversion> <relativePath /> parent>
<dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-webartifactId> dependency> |
spring-boot-starter-web종속성 위에서 , 주어진 모든 종속성을 내부적으로 가져 와서 프로젝트에 추가합니다. 일부 종속성은 직접적이고 일부 종속성은 더 많은 종속성을 전 이적으로 다운로드하는 다른 시작 템플릿을 참조합니다.
또한 버전 정보를 하위 종속성에 제공 할 필요가 없습니다 . 모든 버전은 상위 스타터 버전과 관련하여 해결됩니다 (이 예제에서는 2.0.4.RELEASE).
webmvc 시작 템플릿으로 가져온 종속성
<dependencies> <dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starterartifactId> dependency> <dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-jsonartifactId> dependency> <dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-tomcatartifactId> dependency> <dependency> <groupId>org.hibernate.validatorgroupId> <artifactId>hibernate-validatorartifactId> dependency> <dependency> <groupId>org.springframeworkgroupId> <artifactId>spring-webartifactId> dependency> <dependency> <groupId>org.springframeworkgroupId> <artifactId>spring-webmvcartifactId> dependency> dependencies> |
더 읽기 : 스프링 부트 스타터 템플릿 목록
2. 스프링 부트 자동 설정
@EnableAutoConfiguration주석을 사용하여 자동 구성이 활성화됩니다 . 스프링 부트 자동 구성은 클래스 경로를 스캔하고 클래스 경로에서 라이브러리를 찾은 다음 가장 적합한 구성을 추측 한 다음 마지막으로 이러한 Bean을 모두 구성합니다.
자동 구성은 가능한 한 지능적으로 수행하려고 시도하며 사용자가 더 많은 구성을 정의 할 때 뒤로 물러납니다.
자동 구성은 사용자 정의 Bean이 등록 된 후에 항상 적용됩니다.
스프링 부트 자동 구성 로직은 spring-boot-autoconfigure.jar에 구현되어 있습니다. Yoy는 여기 에서 패키지 목록을 확인할 수 있습니다.
스프링 부트 자동 구성 패키지
예를 들어 Spring AOP의 자동 구성을 살펴보십시오. 다음을 수행합니다.
- 스캔 클래스 경로 를 확인하려면 EnableAspectJAutoProxy, Aspect, Advice및 AnnotatedElement클래스가 존재한다.
- 클래스가 없으면 Spring AOP에 대한 자동 구성이 수행되지 않습니다.
- 클래스가 발견되면 AOP가 Java 구성 어노테이션으로 구성됩니다 @EnableAspectJAutoProxy.
- 또는 spring.aop값이 될 수있는 속성 을 확인합니다 .truefalse
- 속성 값에 따라 proxyTargetClass속성이 설정됩니다.
AopAutoConfiguration.java
@Configuration @ConditionalOnClass({ EnableAspectJAutoProxy.class, Aspect.class, Advice.class, AnnotatedElement.class }) @ConditionalOnProperty(prefix = "spring.aop", name = "auto", havingValue = "true", matchIfMissing = true) public class AopAutoConfiguration {
@Configuration @EnableAspectJAutoProxy(proxyTargetClass = false) @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "false", matchIfMissing = false) public static class JdkDynamicAutoProxyConfiguration {
}
@Configuration @EnableAspectJAutoProxy(proxyTargetClass = true) @ConditionalOnProperty(prefix = "spring.aop", name = "proxy-target-class", havingValue = "true", matchIfMissing = true) public static class CglibAutoProxyConfiguration {
}
} |
3. 임베디드 서버
스프링 부트 어플리케이션은 항상 Tomcat 을 임베디드 서버 의존성 으로 포함합니다 . 복잡한 서버 인프라를 요구하지 않고 명령 프롬프트에서 Spring 부팅 응용 프로그램을 실행할 수 있습니다.
원하는 경우 tomcat을 제외하고 다른 내장 서버를 포함시킬 수 있습니다. 또는 서버 환경을 모두 제외시킬 수 있습니다. 모든 구성 기반입니다.
예를 들어, 아래 구성은 바람둥이를 제외 하고 부두 를 내장 서버로 포함합니다.
pom.xml
<dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-webartifactId> <exclusions> <exclusion> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-tomcatartifactId> exclusion> exclusions> dependency>
<dependency> <groupId>org.springframework.bootgroupId> <artifactId>spring-boot-starter-jettyartifactId> dependency> |
4. 애플리케이션 부트 스트랩
애플리케이션 을 실행 하려면 @SpringBootApplication주석 을 사용해야 합니다. 내부적으로 그와 동등의 @Configuration, @EnableAutoConfiguration,와 @ComponentScan함께.
구성 클래스, 파일을 스캔하고 스프링 컨텍스트에 로드 할 수 있습니다 . 아래 예제에서 실행은 main()method로 시작 합니다. 모든 구성 파일로드를 시작하고 구성하고 폴더의 application.properties 파일 에있는 애플리케이션 특성 을 기반으로 애플리케이션을 부트 스트랩 합니다./resources
MyApplication.java
@SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(Application.class, args); } } |
application.properties
### Server port ######### server.port=8080
### Context root ######## server.contextPath=/home |
응용 프로그램을 실행하려면, 당신은 실행할 수 있습니다 main () 메소드를 IDE 같은에서 일식 , 또는 당신은 jar 파일을 구축하고 명령 프롬프트에서 실행할 수 있습니다.
콘솔
$ java -jar spring-boot-demo.jar |
5. 스프링 부트의 장점
- 스프링 부트는 의존성 충돌 을 해결하는 데 도움이됩니다 . 필요한 종속성을 식별하고 가져옵니다.
- 모든 종속성에 대해 호환 가능한 버전 정보가 있습니다. 런타임 클래스 로더 문제를 최소화합니다 .
- "최적화 된 기본 구성"접근 방식은 가장 중요한 부분을 구성하는 데 도움이됩니다. 필요할 때만 재정의하십시오. 그렇지 않으면 모든 것이 완벽하게 작동합니다. 상용구 코드 , 주석 및 XML 구성 을 피하는 데 도움이됩니다 .
- 내장 HTTP 서버 Tomcat을 제공하므로 신속하게 개발하고 테스트 할 수 있습니다.
- eclipse 및 intelliJ idea 와 같은 IDE와의 뛰어난 통합 성을 가지고 있습니다.
6. 스프링 부트 설정
- 스프링 부트 주석
- 스프링 부트 로그인 안내서
- 스프링 부트 – 스프링 부트 스타터 템플릿
- 스프링 부트 – 스타터 부모 의존성
- 스프링 부트 –로드 된 모든 빈을 얻는다
- 스프링 부트 – @SpringBootApplication 및 자동 구성
- 스프링 부트 – 응용 프로그램 루트 변경
- 스프링 부트 – Jetty 서버 설정
- 스프링 부트 – Tomcat 기본 포트
- 스프링 부트 – WAR 패키징 예제
- 스프링 부트 – yml 구성 로깅
- 스프링 부트 – 로깅 속성 구성
- 스프링 부트 – SSL [https]
- 스프링 부트 – CommandLineRunner
- 스프링 부트 – 개발자 도구 모듈 튜토리얼
- Spring Boot – @Bean 및 @Compoment에 응용 프로그램 인수 주입
- 스프링 부트 임베디드 서버 로그
- 스프링 부트 임베디드 Tomcat 구성
7. REST API 및 SOAP 웹 서비스 개발
- 스프링 부트 – REST API
- 스프링 부트 – 저지
- 스프링 부트 – 스프링 증오 예
- 스프링 부트 – REST API의 유효성 검사 요청
- 스프링 부트 – 역할 기반 보안
- 스프링 부트 – SOAP 웹 서비스
- 스프링 부트 – SOAP 클라이언트
- 스프링 부트 2와 ehcache 3 예제
8. 다른 유용한 주제
- 시작시 배너 비활성화
- 스프링 부트 – JSP보기
- 스프링 부트 – 커스텀 PropertyEditor
- 스프링 부트 – @EnableScheduling
- 스프링 부트 – JMSTemplate
- 스프링 부트 – RSS / ATOM 피드
- 리소스 폴더에서 스프링 부트 읽기 파일
https://howtodoinjava.com/spring-boot-tutorials/
Spring Boot Tutorial - HowToDoInJava
Spring Boot is a Spring framework module which provides RAD (Rapid Application Development) feature to the Spring framework. It is highly dependent on the starter templates feature which is very powerful and works flawlessly. 1. What is starter template? S
howtodoinjava.com