SpringBoot(JPA,Gradle)

[SpringBoot] 프로젝트 실행 방법 및 포트 번호 변경

에띠 2022. 6. 17. 17:28
728x90

Rest controller 생성

main > java > 패키지 안에 controller 패키지 생성 후 GetController 클래스 생성

package com.example.day1.controller;

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

@RestController
@RequestMapping("/api") // localhost:8080/api
public class GetController {
    // localhost:8080/api/getMethod(get)
    @RequestMapping(method = RequestMethod.GET, path="/getMethod")
    public String getRequest() {
        return "getRequest() 호출";
    }
}

 

localhost:8080/api/getMethod

만약 "Web server failed to start. Port 8080 was already in user. "에러 메시지가 나오면 포트번호 변경해야 함!

포트번호 변경 : src > main > resource > application.properties

server.port = 포트번호 지정 후 저장

728x90