Spring Boot 시작하기

- #5_3. Spring Boot 웹 페이지 설정


앞서 Whitelabel Error Page 를 띄우기 까지 살펴보았습니다. 이제 정상적인 페이지 호출을 진행하도록 하겠습니다.



  Spring Boot Port 설정


기본적으로 설정된 8080 포트를 80포트로 변환하겠습니다.

( http://localhost:8080 -> http://localhost )




application.properties 파일에 아래 구문을 추가 해 주시면 됩니다.
server.port=80


  Spring Boot 페이지 출력


Whitelabel Error page 가 아닌 Text를 출력 하는 페이지를 작성토록 하겠습니다.



HelloWorld.java 파일을 생성해 주세요.

package com.example;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorld {
    @RequestMapping("/")
    public @ResponseBody String root_test() throws Exception{
        return "Hello World";
    }

    @RequestMapping("/demo")
    public @ResponseBody String demo_test() throws Exception{
        return "데모 페이지에 접속 하셨습니다.";
    }
}

위 HelloWorld.java 파일을 생성 후


여기 까지 생성이 완료되시면

아래와 같은 페이지들을 보실 수 있습니다.



앞서 말씀드린대로 localhost는 각 서버에 맞는 ip를 적어 주시면됩니다.~



  Spring Boot 재가동


Spring-boot를 재가동 해주시면 됩니다.

혹, 기존 Spring-boot 모듈이 떠 있는 상태라면


Windows 작업 관리자 에서 javaw.exe 의 프로세스 끝내기를 하신 후

프로젝트 우클릭(demo) -> Run As -> Java Application 를 진행하세요.


아니면 아래 그림처럼 로그창에서 빨간 버튼을 클릭하신 후 재가동 하셔도 됩니다.



+ Recent posts