인생 디벨로퍼

React/JPA- Spring boot 프로젝트 생성, h2 console 연결, 본문

React

React/JPA- Spring boot 프로젝트 생성, h2 console 연결,

뫄뫙뫄 2024. 2. 19. 16:50
728x90
반응형
Index
   1. Spring boot 프로젝트 생성
   2. yml 설정, RUN
   3. H2 console 연결
더보기

최대한 간단하게 프로젝트를 생성해서, h2 콘솔 db 연결하기.

1. Spring boot 프로젝트 생성

필요한. dependencies 추가해서, 프로젝트 생성

[board-back]

스프링 프로젝트에 필요한 라이브러리 추가.


 

2. yml 설정, RUN

src/main/resources/application.properties 파일을, yml 파일로 변경해줌

server:
  servlet:
    encoding:
      charset: utf-8
      enabled: true

spring:
  datasource:
    url: jdbc:h2:mem:test;MODE=MySQL
    driver-class-name: org.h2.Driver
    username: sa
    password:

  jpa:
    hibernate:
      ddl-auto: create
      naming:
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
  • 서버 설정
  • h2 콘솔 설정 -> 다른 db 로 설정해도 됨
  • jpa 설정

main  을 run 했을때, 하단 콘솔에 스프링 실행되는걸 확인 할 수 있다!

package com.jycoding.book.web;

import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@RestController
public class BookController {

    @GetMapping("/")
    public ResponseEntity<?> findAll() {
        return new ResponseEntity<String>("ok", HttpStatus.OK);
    }

}

테스트 Controller 실행

컨트롤러가 잘 돌아감


3. H2 console 연결

H2 console 를 사용하는 이유?
별도의 데이터베이스를 설치 할 필요가 없고,
서버가 새로 켜질때 마다 처음 세팅된 데이터로 리셋 되기 때문에, 직접 데이터를 수정 할 필요가 없어서 연습용 프로젝트 혹은 개발 초창기에 사용하기 편리하다.

http://localhost:8000/h2-console 접속

나타나는 로그인 화면에, 

서버 포트, class, url, name 등의 정보를 세팅값과 맞춰 주고, Connect 클릭.

테이블 생성된걸 확인 하고, 간단한 select 문을 작성해서 작동 확인 완료

 

728x90
반응형

'React' 카테고리의 다른 글

React 시작하기 : 설치 및 프로젝트 생성  (1) 2024.02.14