
Spring Boot 프로젝트를 생성해보자.
Spring Boot 프로젝트를 생성하는 방법에는 2가지 방법에 있다.
1) Spring.io 활용하여 생성한 후, IDE에서 import
https://start.spring.io/
2) Eclipse에서 생성
여기서는 Eclipse에서 생성해보자.
Help > Eclipse Marcketplace > sts 검색 > Spring Tools 4 Install

File > New > Spring Boot

Name, type, Java version 등을 설정한다.

Spring Web을 선택한다.


주의할 점은, Spring Boot 3.x.x 버전은 Java 17 이상을 지원하기 때문에 Java 11을 사용하려면 Spring Boot 버전을 2.x.x로 바꾸어 주어야 한다. 버전 수정은 pom.xml에서 가능하다.
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.12</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
만약 MSA를 사용하고 싶다면 2.3.1로 낮춰주어야 한다.
jstl, servlet, tomcat, devtool을 추가한다.
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
src/main/resources 아래에 있는 application.properties
# 설정파일 (Properties)
server.port = 8081
spring.mvc.view.prefix=/WEB-INF/views
spring.mvc.view.suffix=.jsp
# 설정파일 (yaml)
server:
port: 8081
spring:
mvc:
view:
prefix: /WEB-INF/views/
suffix: .jsp
New > others > jsp에서 아래와 같은 파일을 생성한다.
webapp/WEB-INF/views/index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>TigerView.jsp</h1>
</body>
</html>
src/main/java 아래에 Tiger.java라는 파일을 생성한다.
package Pack;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class Tiger {
@RequestMapping("/t1")
public String func01() {
System.out.println("index controller");
return "index";
}
}

