Spring

스프링 부트 JPA 에 PostgreSQL 연동해보기

kimc 2022. 9. 21. 23:21
반응형

 

이번 글을 통해 배워 갈 내용

  1. Spring Boot JPA Connect to PostgreSQL

Postgre 서버 설정, Postgre 설치가 안되신 분들은 아래 링크를 방문해주시면 됩니다

https://codemasterkimc.tistory.com/534

 

PostgreSql pgAdmin 서버로 연결해보기

``` PostgreSql pgAdmin 서버로 연결해보기 ``` 이번 글을 통해 배워갈 내용 PostgreSql pgAdmin 서버로 연결해보기 사전 작업 https://codemasterkimc.tistory.com/532 윈도우에 PostgreSql 설치하기 ```..

codemasterkimc.tistory.com

 

 

1.

maven의 경우

pom.xml에 아래와 같이 작성해주고 Load Maven Change 해줍니다

<dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <scope>runtime</scope>
</dependency>

gradle은 여기를 참조해줍니다

https://mvnrepository.com/artifact/org.postgresql/postgresql/42.1.4

 

2.

application.yaml 혹은 application.properties 파일을 수정해줍니다

 

spring.jpa:
    database: postgresql
    hibernate.dialect: org.hibernate.dialect.PostgresSQLDialect
    hibernate.ddl-auto: update
    show-sql: true
properties:
    hibernate.format_sql: true


spring.datasource:
    hikari.maximum-pool-size: 4
    url: jdbc:postgresql://localhost:5432/test
    username: postgres
    password: 비밀번호
    driver-class-name: org.postgresql.Driver

spring:
    sql:
        init:
            platform: postgres

 

그다음

실행하면

디비와 정상적으로 연결된 것을 확인할 수 있습니다

 

 

 


참조 및 인용

https://stackoverflow.com/questions/48307487/setting-up-spring-boot-jpa-postgresql

 

Setting up : Spring boot + jpa + postgresql

after searching for a long time i can't figure out how to work with spring-boot and postgresql. Spring-boot is starting without warnings. The postgres server is running, but i dont know if spring-...

stackoverflow.com

 

 

 

오늘도 즐거운 코딩 하시길 바랍니다 ~ :)

 


 

반응형