Spring 프로젝트 생성 - 현재 기준
https://start.spring.io/ => 사이트에서 프로젝트 생성
-Dependancies에서 저 두 확장자를 검색해서 추가해야 한다.
-설정이 완료되면 Generate 클릭해서 파일을 생성한다. => .zip 파일로 생성
-다운로드 받은 압축파일을 풀어 인텔리제이에 프로젝트 생성
-Maven 이나 Gradle은 의존관계를 관리해준다.
필요한 라이브러리를 설치하게 되면 그 라이브러리에 필요한 라이브러리를 자동적으로 땡겨온다.
스프링 부트 라이브러리
- spring-boot-starter-web
- spring-boot-starter-tomcat: 톰캣 (웹서버)
- spring-webmvc: 스프링 웹 MVC
- spring-boot-starter-thymeleaf: 타임리프 템플릿 엔진(View)
- spring-boot-starter(공통): 스프링 부트 + 스프링 코어 + 로깅
- spring-boot
- spring-core
- spring-boot-starter-logging
- logback, slf4j
- spring-boot
테스트 라이브러리
- spring-boot-starter-test
- junit: 테스트 프레임워크
- mockito: 목 라이브러리
- assertj: 테스트 코드를 좀 더 편하게 작성하게 도와주는 라이브러리
- spring-test: 스프링 통합 테스트 지원
-요즘 개발은 라이브러리 하나를 빌드한 후, 웹서버에 띄우면 자동적으로 그에 필요한 작업을 진행해줌.
-실무에서는 로깅을 많이 사용해야한다.
-윈도우 기준 File -> setting -> BuildTools에 Gradle에서 Build and run using 과 Run tests using을 intelliJ로 변경해준다.
View 환경설정
welcome Page 만들기
resources-> static 폴더에 index.html 파일 추가
index.html 파일은 간단하게 작성한다.
package hello.hellospring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloController {
@GetMapping("hello") // '/hello'라고 url에 입력하면 작동.
public String hello(Model model){
model.addAttribute("data", "hello!!"); //모델에 "data"로 데이터 저장
return "hello";
}
}
Spring Boot는 정적(static) 및 템플릿(templated)에 welcome Page를 모두 지원한다. 먼저, Spring Boot는 구성된 정적 콘텐츠 위치에서 index.html 파일을 찾아서 어느 하나라도 발견되면 해당 파일은 애플리케이션의 welcome Page로 자동으로 사용된다.
빌드하고 실행하기(윈도우 기준)
- 명령프롬프트 실행
- 생성한 spring 파일경로로 이동
-> cd 파일경로
- gradlew.bat 파일을 실행한다. (build 진행)
-> 해당 파일 경로에서 gradlew 입력 후 엔터.
'Spring' 카테고리의 다른 글
MVC 패턴 (0) | 2023.10.15 |
---|---|
HTTP 요청 및 응답 (0) | 2023.10.10 |
웹 애플리케이션 이해 (0) | 2023.10.06 |
AOP (Aspect Oriented Programming) (0) | 2023.10.03 |
JPA(Java Persistance API) (0) | 2023.09.30 |