관리 메뉴

코딩하는 락커

[Spring Boot를 이용한 RESTful Web Services 개발] 6~7강 본문

🍃 Spring/🌱 Spring Boot를 이용한 RESTful Web Service

[Spring Boot를 이용한 RESTful Web Services 개발] 6~7강

락꿈사 2022. 2. 4. 15:37

스프링 설정 파일

Pom.xml : 전체 프로젝트에 필요한 Maven 설정을 지정하는 파일

application.properties : 스프링 설정을 할 수 있는 파일. (yml 파일로 변경함)

 

포트 번호 변경 (application.yml에 작성)

server:
  port: 8088

 

간단한 Rest Controller 만들기

  • com.example.restfulservice 패키지에 HelloWorldContoller.java 파일 생성
  • GET 방식의 메소드 사용
  • URI : /hello-world (URI는 사용자에 의해 호출되는 end-point)
  • 기존방식은 @RequestMapping()을 썼지만 스프링 4.0이후로 어노테이션으로 바로 메소드 지정 가능해짐
@RequestMapping(method=RequestMethod.GET, path="/hello-word")
@GetMapping(path="/hello-world")
package com.example.restfulwebservice;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {

    @GetMapping(path = "/hello-world")
    public String helloworld(){
        return "Hello World";
    }
}

 

 

Comments