강의

멘토링

로드맵

Inflearn Community Q&A

potatomango's profile image
potatomango

asked

Microservice Application (MSA) Development with Spring Cloud

Catalogs Microservice - Feature Implementation ②

H2 최신 버전 사용 시 server mode 사용에 따른 application.yml 파일 설정(테이블은 생성됐는데 data.sql INSERT 안될 시 참고)

Written on

·

1.3K

13

Spring Boot 3.XX 대 버전으로 최신 버전 사용 시 H2를 이전 버전으로 사용 불가합니다.

따라서 H2를 따로 켜서 실행해준 후, catalog-service에서 Server mode로 연결하던지 따로 켜 둔 H2를 연결하던지 선택해야합니다.

 

이 때, Server Mode로 프로젝트와 H2를 연결시키면 강의 내용의 설정만으로는 data.sql의 INSERT 쿼리문이 동작하지 않습니다.

 

그렇기 때문에 관련 설정을 application.yml에 추가해주어야 하는데요. 아래와 같이 설정하면 됩니다. stackoverflow와 강사님의 2021년 답변을 참고하여 해결하였습니다.

 

server:
  port: 0

spring:
  application:
    name: catalog-service
  h2:
    console:
      enabled: true
      settings:
        web-allow-others: true
      path: /h2-console
  datasource:
    driver-class-name: org.h2.Driver
    url: jdbc:h2:tcp://localhost/mem:testdb
    username: sa
  jpa:
    hibernate:
      ddl-auto: create-drop
    show-sql: true
    generate-ddl: true
    defer-datasource-initialization: true
  sql:
    init:
      mode: always

eureka:
  instance:
    instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}
  client:
    register-with-eureka: true
    fetch-registry: true
    service-url:
      defaultZone: http://localhost:8761/eureka

logging:
  level:
    com.example.catalogservice: DEBUG

 

추가한 내용은 spring.jpa.defer-datasource-initialization과 spring.sql.init.mode 설정입니다.

architecturejpaJPAspring-booth2spring-cloudKafka최신버전msa

Quiz

67% of people got it wrong. Give it a try!

이 마이크로서비스 아키텍처에서 API Gateway의 주요 역할은 무엇일까요?

복잡한 비즈니스 로직을 직접 수행한다.

클라이언트 요청의 단일 진입점을 제공하고 올바른 마이크로서비스로 라우팅한다.

모든 마이크로서비스의 데이터를 저장하는 중앙 데이터베이스 역할을 한다.

백그라운드 예약된 작업을 처리한다.

Answer 2

1

감사합니다

0

감사합니다.

potatomango's profile image
potatomango

asked

Ask a question