Gradle은 의존관계가 있는 라이브러리를 함께 다운로드 한다.
Maven or Gradle: 필요한 라이브러리를 당겨오고, 빌드하는 라이프 사이클까지 관리해주는 툴.
java
SNAPSHOT, M1 등: 아직 만들고 있는 버전, 정식 release 되지 않음
Group 기업명
Artifact 빌드 되어 나오는 결과물 (프로젝트명)
어떤 라이브러리를 당겨 쓸 거냐.
압축 파일 다운로드 후 IntelliJ로 Open
src > main / test
요즘은 main
과 test
폴더가 기본적으로 분리 되어 있는 추세.
src > main > java
> 애플리케이션 코드
src > main > resources
> .java 파일을 제외한 properties같은 설정 파일이나 xml, 리소스들
src > test
> test 코드
build.gradle
의존성 설정 파일, mavenCentral
에서 필요한 라이브러리들을 다운로드
.gitignore
필요한 소스코드만 git에 올라가도록 설정해주는 파일
main 실행 시 8080 포트에서 내장 Tomcat 서버가 열림
스프링 부트 라이브러리
테스트 라이브러리
Welcome Page: 도메인만 누르고 들어왔을 때 첫 화면
스프링부트는 static content location에서 index.html
을 찾고 웰컴 페이지를 렌더링
src > main > resources > static
: index.html
<!DOCTYPE HTML>
<html>
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Hello
<a href="/hello">hello</a>
</body>
</html>
: 파일을 웹 브라우저에 그대로 넘겨주는 정적 페이지
컨트롤러: 웹 애플리케이션의 첫번째 진입점
@Controller
어노테이션 달아줘야 함.@GetMapping("hello")
: 웹 애플리케이션에서 /hello
에 들어오면 이 메서드가 호출됨.resources/templates/hello.html
에 아래와 같이 복사
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'안녕하세요. ' + ${data}" >안녕하세요. 손님</p>
</body>
</html>
웹 브라우저에서 localhost:8080/hello라고 던지면, 스프링에 내장된 톰캣 웹 서버가 @GetMapping("hello")
된 helloController의 메소드 실행.
Spring이 Model을 만들어 메소드에 넣어주는데, 모델에 key:data value:hello!!로 addAttribute
했음.
"hello"라는 문자열을 리턴 → resources/templates/hello
를 찾아 렌더링
resources:templates/
+{ViewName}+ .html
./gradlew build
→ build
폴더 생성됨cd build/libs
→ hello-spring-0.0.1-SNAPSHOT.jar 생성됨java -jar hello-spring-0.0.1-SNAPSHOT.jar
서버 배포시에는 생성된 .jar
파일만 복사해서 서버에 넣고 실행하면 됨.
cf) build 폴더 삭제 후 다시 빌드 ./gradlew clean build