Project & Issu

JWT 연습

gu9gu 2023. 2. 10. 16:31

Json Web Token

 

스프링 시큐리티 공부 18 - JWT (Json Web Token) (tistory.com)

JWT 자바 가이드. 이 글은 OAuth와 JSON Web Token과 같은 토큰 기반의… | by Out of Bedlam | Medium

 

server:
  port: 8080
  servlet:
    context-path: /
    encoding:
      charset: UTF-8
      enabled: true
      force: true

spring:
  datasource:
    # h2 연결용 DB 정보
    driver-class-name: org.h2.Driver # Database를 H2로 사용하겠다.
    # url: jdbc:h2:~/test  # H2 접속 정보
    # url: jdbc:h2:tcp://localhost/~/test
    username: sa
    password:

    # MySQL 연결용 DB 정보
#    driver-class-name: com.mysql.cj.jdbc.Driver
#    url: jdbc:mysql://localhost:3306/security?serverTimezone=Asia/Seoul
#    username: cos
#    password: cos1234

  jpa:
    hibernate:
      ddl-auto: create #create update none
      naming:
        #SpringPhysicalNamingStrategy(Default)  =>  camel case를 underscore 형태로 변경
        #PhysicalNamingStrategyStandardImpl   =>  변수 이름을 그대로 사용
        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
    show-sql: true

 

 

H2 DB로 연결 테스트

Generic H2 (Embedded)를 선택하고 JDBC URL에 jdbc:h2:~/test를 입력하고 연결을 클릭한다.

test라는 데이터베이스가 생성되며, 생성할 데이터베이스 이름을 다른걸로 하고싶으면 test 말고 다른 이름을 입력하면 된다.

 

다시 첫화면으로 가서

저장한 설정: Generic H2 (Server)

JDBC URL: jdbc:h2:tcp://localhost/~/test

를 입력하고 연결을 클릭한다.

 

데이터베이스 파일을 생성한 다음에 JDBC URL을 저렇게 변경하는 이유는 파일 직접 접근이 아닌 TCP 소켓을 통해 접속해야 어플리케이션과 콘솔이 동시에 접근했을 때 오류가 발생하지 않기 때문이다.

 

 

 

 

 

에러

2023-02-14 19:21:26.844 ERROR 5108 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.IllegalStateException: Cannot call sendError() after the response has been committed] with root cause