LinkedNestBlog

Spring Boot와 Spring의 차이점

by Dev Jinwon
# **Spring Boot와 Spring의 차이점**
<hr/>
- 기존 Spring의 경우, 기본 프로젝트를 생성하는데 Transaction Manager, Hibernate Datasource, Entity Manager, Session Factory 등의 설정을 위해 많은 시간이 소요.
- Spring Boot는 Spring-Starter prefix로 시작되는 프레임워크 의존성 관리를 통해 초기 기본 설정을 해야 했던 부분을 간단하게 사용 가능하게 됨.

- 참고. Spring-Starter Projects

~~~
spring-boot-starter-web-services : SOAP 웹 서비스
spring-boot-starter-web : Web, RESTful 응용프로그램
spring-boot-starter-test : Unit testing, Integration Testing
spring-boot-starter-jdbc : 기본적인 JDBC
spring-boot-starter-hateoas : HATEOAS 기능을 서비스에 추가
spring-boot-starter-security : 인증과 권한
~~~

# **Spring Boot의 장점은?**
<hr/>

1. Spring-Starter Projects를 이용한 라이브러리 관리 자동화
2. 설정의 자동화
- 프로젝트에 추가된 라이브러리를 기반으로 실해에 필요한 환경을 자동으로 설정
- 기존처럼 초기 프로젝트 시작을 위한 설정에 시간을 쏟아붓지 않아도
3. 라이브러리 버전 자동 관리
- Spring Boot 버전에 ㅐ당하는 Spring Library 및 3 party library들도 호환되는 버전으로 다운로드
4. 테스트
- JUnt 등의 테스트 관련 라이브러리들이 기본적으로 포함.
- 컨트롤러, 서비스 등의 다양한 레벨에서 테스트 케이스를 작성하여 테스트 가능
5. 내장 Tomcat
6. 독립적으로 실행 가능한 JAR
- Spring은 웹프로젝트라면 WAR로 패키징 해야했지만
- SPring Boot는 WAR 뿐 아니라 JAR로 패키징하여 사용할 수 있다.


# **Spring Boot Web Project Creation**
<hr/>

Ref.]
- spring boot document : https://docs.spring.io/spring-boot/docs/current/reference
- test source code git repository : https://github.com/jwlee0208/test

**SpringBoot 사용시 참고사항**
1. intellij community 버전도 사용 가능
- Download URL : https://www.jetbrains.com/ko-kr/idea/download/#section=windows
2. view 페이지 수정 후 server re-start를 하지 않기 위해서는 spring-boot-devtools 를 사용해야 함
~~~ gradle
## build.gradle 파일 > dependencies 영역에 아래 내용 추가
implementation 'org.springframework.boot:spring-boot-devtools'
~~~
3. 프로젝트 빌드를 jar로
3.1. build
3.1.1. windows os 에서는 gradlew.bat를 실행
3.1.2. mac os에서는 ./gradlew(혹은 ./gradlew clean build)를 실행
-> 프로젝트명 ......jar파일 생성
3.2. 실행
- java -jar 'jar파일 명' 실행
- tomcat 설치 불필요

4. page directory 기본 구조
- 정적 페이지는 /resources/static 하위
- 동적 페이지는 /resources/templates 하위에 위치


- 일반적인 web application 구조
- controller - service - repository - DB
- repository : DB 접근. domain 객체를 DB에 저장하고 관리
- domain : 비즈니스 도메인 객체



- 서비스는 비지니스에 의존적으로 메서드 네이밍을 하는게 좋다











- spring 사용
- MemoryMemberRepository를 JdbcMemberRepository로 변경을 통해 살펴볼 수 있는 장점
- 다형성의 장점
- DI(Dependency Injection)를 통해 기존 코드를 손대지 않고 설정만으로 구현 클래스를 변경할 수 있다.
- 개방 폐쇄 원칙(Open Close Principle)
- 확장에는 열려있고, 수정에는 닫혀있다.
- 기능을 완전히 수정을 해도 어플리케이션 전체를 수정할 필요가 없다.


ref.] intellij에서 단축키
- 파라미터 정보 커맨드 사용 : ctrl + p
- 자동완성 : ctrl + shift + enter
- getter/setter 생성 : ctrl + enter
- method refectoring(create new method) : ctrl + alt + m
- junit class 자동 생성 : ctrl + shift + t
- undo : ctrl + z
Spring Boot와 Spring의 차이점 · LinkedNest Blog