Web/Spring, SpringBoot

Spring boot 프로젝트 설정

조용우 2023. 4. 9. 08:51

https://start.spring.io/

필요 Dependency 선택 후 Generate

Spring Web, Spring Security, Spring Data JPA, MySQL driver, Lombok, Spring Boot Dev Tools, Thymeleaf

 

application.yml 파일

server:
  port: 8000 #포트
  servlet:
    context-path: /blog #시작 path
    encoding:
      charset: UTF-8
      enabled: true
      force: true

spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/blog?serverTimezone=Asia/Seoul
    username: DB 아이디
    password: DB 비밀번호

  jpa:
    open-in-view: true # 영속성 컨텍스트를 프레젠테이션 계층 (Controller 전) 까지 가져감. -> Lazy Loading을 가능하게 해줌
    hibernate:
      ddl-auto: create # 프로젝트 실행 시 테이블 새로 생성
      naming:
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl # Entity table을 만들 때, column명을 변수명 그대로 (Camel case)
        					# org.hibernate.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy # snake_case로 변경
    show-sql: true # console에 sql문 표시
    properties:
      hibernate.format_sql: true # console에 sql문 예쁘게 표시
      id:
        new_generator_mappings: false # JPA 기본 넘버링 전략

  jackson:
    serialization:
      fail-on-empty-beans: false

 

Git 설정

git init
git add .
git commit -m "환경설정 완료"
git remote add origin 주소
git push origin master

 

Spring Boot Dev Tools 자동 빌드 세팅

https://barbera.tistory.com/47