Docker PostgreSQL 사용법
도커설치는 따로 설명하지 않음
#도커를 통한 설치
$ docker run -p 5432:5432 -e POSTGRES_PASSWORD=pass -e POSTGRES_USER=shinilhyun
-e POSTGRES_DB=springboot --name psql_boot -d postgres
#도커를 통한 포스트그레스 bash 실행
$ docker exec -i -t postgres_boot bash
$ su - postgres
$ psql springboot
<!--PostgreSQL 드라이버 추가-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<!--JPA 의존성 추가-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
spring.datasource.url=jdbc:postgresql://localhost:5432/springboot
spring.datasource.username=shinilhyun
spring.datasource.password=1234
# 개발할때는 create 혹은 update 운영시에는 validate
spring.jpa.hibernate.ddl-auto=create
#실행시 warnning 제거하기 위해
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
#콘솔에 실행된 sql 띄워줌
spring.jpa.show-sql=true
#sql 읽기 쉽게 해줌
spring.jpa.properties.hibernate.format_sql=true
#sql 값을 보게 해줌
logging.level.org.hibernate.type.descriptor.sql=traces
@Component
@Transactional
public class JpaRunner implements ApplicationRunner {
@PersistenceContext
EntityManager entityManager;
@Override
public void run(ApplicationArguments args) throws Exception {
Account account = new Account();
account.setUsername("ilhyun");
account.setPassword("jpa");
entityManager.persist(account);
}
}