JSCODE Logo
프로그래밍 과외블로그후기멘토진
회사명 : JSCODE대표 : 박재성사업자 등록번호 : 244-22-01557통신판매업 : 제 2023-인천미추홀-0381 호
학원 명칭 : 제이에스코드(JSCODE)원격학원학원설립ㆍ운영 등록번호 : 제6063호

서울특별시 구로구 경인로 20가길 11(오류동, 아델리아)

Copyright ⓒ 2025 JSCODE - 최상위 현업 개발자들의 프로그래밍 교육 All rights reserved.

이용약관개인정보처리방침
← 블로그 목록으로 돌아가기

[실습] Board Microservice 만들기

JSCODE 박재성
JSCODE 박재성
2025-12-06
author
JSCODE 박재성
category
MSA
createdAt
Dec 6, 2025
series
비전공자도 이해할 수 있는 MSA 입문/실전
slug
practice-create-board-microservice
type
post
updatedAt
Dec 6, 2025 05:43 AM

✅ Board Microservice 만들기

User Service는 만들었으니 마지막으로 남은 Board Service를 만들어보자.
notion image
 
 

✅ Spring Boot 프로젝트 셋팅 & DB 연결

  1. Spring Boot 프로젝트 셋팅
    1. start.spring.io
      https://start.spring.io/
      notion image
      • Artifact와 Name을 board-service라고 지어주자.
      • Package name을 Java 컨벤션에 맞게 boardservice라고 지어주자.
      • Java 21 버전을 선택하자. 아래 과정을 Java 21 버전을 기준으로 진행할 예정이다.
      • Dependencies는 Spring Boot DevTools, Spring Web, MySQL Driver, Spring Data JPA를 선택하자.
       
  1. application.yml 작성하기
    1. 이 프로젝트에서는 application.properties를 지우고 application.yml을 생성했다.
      server: port: 8081 spring: datasource: url: jdbc:mysql://localhost:3307/board-db # DB 주소 username: root # DB 계정 password: password # DB 비밀번호 driver-class-name: com.mysql.cj.jdbc.Driver jpa: hibernate: ddl-auto: update show-sql: true
       
  1. Spring Boot 서버 실행시켜서 DB 연결 제대로 되는 지 확인하기
    1. Spring Boot 실행시켰을 때 아래와 같은 에러 안 뜨고 서버가 실행되면, 정상적으로 DB가 잘 연결된 것이다.
      notion image
       
 

✅ 게시글 생성 API 만들기

  1. Board 엔티티 생성하기
    1. domain/Board
      @Entity @Table(name = "boards") public class Board { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long boardId; private String title; private String content; private Long userId; // FK 설정 안하고 그냥 컬럼으로 선언 public Board() { } public Board(String title, String content, Long userId) { this.title = title; this.content = content; this.userId = userId; } public Long getBoardId() { return boardId; } public String getTitle() { return title; } public String getContent() { return content; } public Long getUserId() { return userId; } }
       
  1. Repository 만들기
    1. domain/BoardRepository
      public interface BoardRepository extends JpaRepository<Board, Long> { }
       
  1. Controller 만들기
    1. controller/BoardController
      @RestController @RequestMapping("/boards") public class BoardController { private final BoardService boardService; public BoardController(BoardService boardService) { this.boardService = boardService; } @PostMapping public ResponseEntity<Void> create( @RequestBody CreateBoardRequestDto createBoardRequestDto ) { boardService.create(createBoardRequestDto); return ResponseEntity.noContent().build(); } }
       
  1. DTO 만들기
    1. dto/CreateBoardRequestDto
      public class CreateBoardRequestDto { private String title; private String content; private Long userId; public String getTitle() { return title; } public String getContent() { return content; } public Long getUserId() { return userId; } }
       
  1. Service 만들기
    1. service/BoardService
      @Service public class BoardService { private final BoardRepository boardRepository; public BoardService(BoardRepository boardRepository) { this.boardRepository = boardRepository; } @Transactional public void create(CreateBoardRequestDto createBoardRequestDto) { Board board = new Board( createBoardRequestDto.getTitle(), createBoardRequestDto.getContent(), createBoardRequestDto.getUserId() ); this.boardRepository.save(board); } }
       
  1. 서버 다시 실행시키기
    1. notion image
       
  1. API 잘 작동하는 지 테스트해보기
    1. notion image
      주의) 8081번 포트로 요청을 보내야 한다.
 
  1. DB에 데이터 잘 들어갔는 지 확인하기
    1. notion image
 
author
JSCODE 박재성
category
MSA
createdAt
Dec 6, 2025
series
비전공자도 이해할 수 있는 MSA 입문/실전
slug
type
series-footer
updatedAt
Dec 6, 2025 05:45 AM
📎
이 글은 비전공자도 이해할 수 있는 MSA 입문/실전 강의의 수업 자료 중 일부입니다.