Spring Boot 기반으로 Spring 관련 프로젝트를 만들어주는 사이트
Maven
Gradle
Main VS Test
[IntelliJ] 아파치 톰캣 설정 및 JSP 실행 방법
application.properties 파일을 이용해서 톰캣의 Default port인 8080을 다른 포트번호로 변경할 수도 있다.
# application.properties
server.port=8090
만약 0으로 포트번호를 지정하면 랜덤으로 사용가능한 비어있는 포트번호로 지정이 된다.
# application.properties
server.port=0
Spring boot starter web만 가져오면, web과 관련된 모든 필요한 것들을 자동으로 땡겨온다.
Gradle이 의존관계를
예전에는 개발할 때, Web server(WAS)를 직접 서버에 설치를 해놓고, 거기에 자바코드를 밀어넣는 형식으로 웹 서버와 개발 라이브러리를 완전히 분리해놓았다.
( → 톰캣 서버 설치하고~~ = 매우 힘든 작업이었음 )
요즘에는 소스 라이브러리에서 웹서버를 이미 들고 있다. ( embeded, 내장 웹 서버 )
⇒ Spring Boot를 쓰면 Spring core까지 다 땡겨와서 편하다 !!
slf4j : 인터페이스
logback : 실제 log를 어떤 구현체로 출력을 할 것인지 정하는 것, 성능빠르고 기능지원도 다양
spring에서는 slf4j + logback을 default로 땡겨온다.
<!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>
static/index.html
을 올려두면 Welcome page 기능을 제공한다.@Controller
public class HelloController {
@GetMapping("hello")
public String hello(Model model) {
model.addAttribute("data", "hello!!");
return "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>
실행: http://localhost:8080/hello
Oracle 포트를 8080으로 해두었기 때문에 8090으로 포트번호를 변경해서 확인한다.
But default값은 8080임.
resources:templates/ +{ViewName}+ .html
./gradlew gradlew.bat
를 실행하면 됩니다.gradlew
하고 엔터를 치면 됩니다.gradlew build
dir