본문 바로가기

Spring/Spring Boot 기초

Spring Boot - Welcome Page 만들기

프로젝트 셋팅 방법 : 

https://jin2rang.tistory.com/entry/Spring-Boot-%EC%85%8B%ED%8C%85%ED%95%98%EA%B8%B0-startspringio

 

프로젝트 기초적인 셋팅을 완료한 뒤 View의 Welcome Page를 띄워보려고 한다.


 

 

프로젝트 우클릭 >  Run As > Spring Boot App을 실행하면 프로젝트가 실행이된다.

Spring Boot에는 tomcat이 내장되어 있기 때문에 바로 실행할 수 있다.

console창에서는 8080포트로 동작한다는 로그를 볼 수 있다.

 

 

 

브라우저에서 http://localhost:8080으로 들어가보면 에러 페이지를 볼 수 있다.

에러가 나는 이유는 해당 포트로 실행했을 때 동작하는 웹 페이지가 없기 때문이다.

 

 

 


간단하게 Welcome Page(홈화면)를 이제 만들어 보려고 한다!

Welcom Page(홈화면)는 도메인만 입력하고 들어왔을 때 보여지는 페이지이다.

Spring Boot는 static경로에서 index.html을 먼저 찾고, 만약에 못찾으면 index template에서 찾는다.

스프링 레퍼런스에 보면 다음과 같이 설명이 나와있다.
(https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-welcome-page)

7.1.6. Welcome Page
Spring Boot supports both static and templated welcome pages. It first looks for an index.html file in the configured static content locations. If one is not found, it then looks for an index template. If either is found, it is automatically used as the welcome page of the application.

 

프로젝트 내부에
src/main/resources/static/index.html

이 경로에 index.html파일을 생성한다!

<!DOCTYPE HTML>
<html>
<head>
 <title>Hello Jin2rang Page</title>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
  I'm jin2rang
  <a href="/jin2rang/blog">Hello ~! </a>
</body>
</html>

 

index.html에 위의 html태그를 입력 후,
다시 http://localhost:8080를 들어가보면 다음과 같은 화면을 확인 할 수 있다!

 

 

 

 

기본적으로 화면 띄우는 것을 완료했으니,

템플릿 엔진이라는 것을 이용하여 View를 기본적으로 환경설정하는 것을 해보려고 한다!