그라가승훈
[유튜브-메타코딩] - 나만의 블로그 만들기 - 5. Yaml(야믈), yml 설정 (JSP 파일 연동) 본문
- Yaml이란?
- 기존 XML, JSON 형식 파일의 포맷을 더 가볍고 가독성이 좋게 만든 파일이다.
- web.xml, root-context.xml, servlet-context.xml의 합본
- Yaml 설정
- application.yml 코드와 설명
- server
- 기본적으로는 ‘ port : 8080, contetxt-path : / ’ 경로로 되어있다.
- localhost:8000/blog/ 로 시작 주소를 변경한다는 것이다.
server: port: 8000 servlet: context-path: /blog encoding: charset: UTF-8 enabled: true force: true
- sprin.mvc(JSP 파일 연동)
- .jsp 경로를 설정한 이유는 스프링 부트는 기본적으로 jsp사용이 권장하기 않기 때문에 timeleaf 같은 다른 템플릿 엔진을 사용해야 한다. 하지만 jsp를 사용하기 위해서는 해당 구조로 폴더 구성을 한 뒤 세팅하여야 한다. (jasper)
- jsp 파일 연동을 위해서 2개의 설정을 해줘야 하는데 그중 1개는 의존성 설정의 jasper와 이것이다.
- jsp 파일은 톰캣이 컴파일하여 html 파일로 변환 후 브라우저에 보여준다.
mvc: view: prefix: /WEB-INF/views/ suffix: .jsp
- spring.datasource
- DB 드라이버와 유저, 암호를 설정
- datasource 의 mysql 드라이버에 cj가 들어간 이유는 mysql 6점대 이상 버전부터는 해당 드라이버를 사용하고 그 이전 드라이버는 cj가 없는 com.mysql.jdbc.Driver를 사용한다.
datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/blog?serverTimezone=Asia/Seoul username: cos password: 1234
- spring.jpa
- ddl-auto
- create - 서버 시작 시마다 DB초기화
- update - 수정사 항만 DB에 반영
- none - DB에 아무런 반영을 하지 않음.
- physical-strategy
- org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
- 엔티티를 만들 때 변수명 그대로 DB에 필드를 만들어 준다.
- org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
- 엔티티를 만들 때 변수명에 언더스코어를 붙여준다. 예) createDate -> create_dat
- use-new-id-generator-mappings: false
- use-new-id-generator-mappings 는 mysql로 말하면 auto_increment 오라클로 말하면 시퀀스를 어떤 식으로 사용할지 방식을 결정하는 것인데 false를 하면 jpa가 사용하는 기본 넘버링 전략을 따라가지 않는다는 뜻이고 true를 하면 기본 넘버링 전략을 따라간다는 뜻이다.
- show-sql : true 는 테이블을 생성하면 콘솔 창에 생성된 테이블을 보여준다.
- properties.hibernate.format_sql: true로 콘솔창에 보이는 테이블을 정렬해서 보여준다.
jpa: open-in-view: true hibernate: ddl-auto: create naming: physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl use-new-id-generator-mappings: false show-sql: true properties: hibernate.format_sql: true
- ddl-auto
- spring.jackson
- server
jackson:
serialization:
fail-on-empty-beans: false
- 전체 코드
server:
port: 8000
servlet:
context-path: /blog
encoding:
charset: UTF-8
enabled: true
force: true
spring:
mvc:
view:
prefix: /WEB-INF/views/
suffix: .jsp
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/blog?serverTimezone=Asia/Seoul
username: cos
password: cos1234
jpa:
open-in-view: true
hibernate:
ddl-auto: create
naming:
physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
use-new-id-generator-mappings: false
show-sql: true
properties:
hibernate.format_sql: true
jackson:
serialization:
fail-on-empty-beans: false
'Spring' 카테고리의 다른 글
[유튜브-메타코딩] - 나만의 블로그 만들기 - 7. 더미 데이터로 테스트 (0) | 2022.08.11 |
---|---|
[유튜브-메타코딩] - 나만의 블로그 만들기 - 6. Blog 테이블 만들기 (User, Board, Reply) (0) | 2022.08.10 |
[유튜브-메타코딩] - 나만의 블로그 만들기 - 4. HTTP1.1 요청방식 (0) | 2022.08.08 |
[유튜브-메타코딩] - 나만의 블로그 만들기 - 3. Git 세팅 (0) | 2022.08.08 |
[유튜브-메타코딩] - 나만의 블로그 만들기 - 2. 의존성 설정 및 DB세팅 (0) | 2022.08.07 |
Comments