각진 세상에 둥근 춤을 추자

[Spring Boot] MAC 스프링부트 설치 및 개발환경 구축 본문

Spring

[Spring Boot] MAC 스프링부트 설치 및 개발환경 구축

circle.j 2023. 1. 10. 00:53
1. Spring Tools 4 for Eclipse (STS4) 설치하기 

 

(1) 아래 홈페이지에서 STS4 다운받기 

https://spring.io/tools

 

Spring Tools 4 is the next generation of Spring tooling

Largely rebuilt from scratch, Spring Tools 4 provides world-class support for developing Spring-based enterprise applications, whether you prefer Eclipse, Visual Studio Code, or Theia IDE.

spring.io

 

맥북 인텔칩 - 4.17.1 MACOS X86_64

 

 

설치 완료 후 스프링부트 실행 화면

 

(2) Help - Eclipse MarketPlace - 'Eclipse Web Developr Tools 3.28' 설치

 

 


2. Spring Boot Project 생성하기

 

[File] - [New] - [Spring Starter Project] 

 

  • Name: 프로젝트명
  • Type: Gradle - Groovy
  • Packaging: Jar
  • Java Version: 11
  • Language: Java
  • Group, Package: kr.co.패키지명

 

  • Spring Boot Version: 2.7.7
  • Selected: Spring boot DevTools, Lombok, Thymeleaf, Spring Web

 

Do you wish to enable additional Java sources reconciling to get Spring specific validations and suggestions? YES

 

프로젝트 실행하기 - 프로젝트 마우스 우클릭 - Run As - 5 Spring Boot App 

 

Spring 실행

 

http://localhost:8080 접속

 


3. Page 생성하기

 

(1) 프로젝트 - src/main/java - kr.co.ch06 - Ch06Application.java

package kr.co.ch06;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@SpringBootApplication
public class Ch06Application {

	public static void main(String[] args) {
		SpringApplication.run(Ch06Application.class, args);
	}

}

 

(2) 프로젝트 - src/main/java - kr.co.ch06.controller 생성 - MainController.java 생성

package kr.co.ch06.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import kr.co.ch06.vo.UserVO;

@Controller
public class MainController {
	
	@GetMapping(value = {"/", "/index"})	
	public String index() {
		return "/index";
	}
	@GetMapping("/hello")
	public String hello() {
		return "/hello";
	}
	
	@GetMapping("/welcome")
	public String welcome() {
		return "/welcome";
	}
	
	@GetMapping("/greeting")
	public String greeting() {
		return "/greeting";
	}
	
}

 

(3) 프로젝트 - src/main/resources - templates - index.html 생성

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
	<head>
            <meta charset="UTF-8">
            <title>index</title>
	</head>
	<body>
            <h3>스프링부트 실습</h3>

            <a href="/hello">hello</a>
            <a href="/welcome">welcome</a>
            <a href="/greeting">greeting</a>
	</body>
</html>

 

(4) 프로젝트 - src/main/resources - templates - hello.html, welcome.html, greeting.html 생성

hello.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>hello</title>
</head>
<body>
    <h3>Hello Spring Boot</h3>
    <a href="/">메인</a>
</body>
</html>

 

welcome.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>welcome</title>
</head>
<body>
    <h3>Welcome Spring Boot</h3>
    <a href="/">메인</a>
</body>
</html>

 

greeting.html

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>greeting</title>
</head>
<body>
    <h3>Greeting Spring Boot</h3>
    <a href="/">메인</a>
</body>
</html>

 

(5) 프로젝트 마우스 우클릭 - Run As - 5 Spring Boot App + localhost:8080 접속