[서버][스프링] DB 관련 property 알아보기

프로그래밍/서버2021. 3. 10. 23:05

application.yml 또는 application.properties에서 쓰이는 DB 관련 프러퍼티에 대해 간단히 알아보겠습니다.

 

spring.jpa.database: "POSTGRESQL"

작동할 대상 DB를 지정합니다. 자동 감지된 것이 기본적으로 사용됩니다.

"databasePlatform" 프로퍼티를 사용하여 설정할 수도 있습니다.

 

spring.datasource.platform: "postgres"

schema-${platform}.sql 나 data-${platform}.sql와 같은 DDL 또는 DML에서 사용할 플랫폼

 

*DDL : Data Defination Language

*DML : Data Manipulation Language

*docs.spring.io/spring-boot/docs/2.1.x/reference/html/howto-database-initialization.html#howto-initialize-a-database-using-hibernate

*docs.spring.io/spring-boot/docs/2.1.x/reference/html/howto-database-initialization.html#howto-initialize-a-database-using-spring-jdbc

spring.jpa.show-sql: "true"

디버깅을 위해 생성된 SQL을 로그에서 보여주는 것을 설정하는 부분

 

spring.database.driverClassName: "org.postgresql.Driver"

spring.datasource.driverClassName가 올바른 이름입니다. JDBC Drive의 이름을 적는 곳입니다. 기본적으로는 spring.datasource.url를 기반으로 자동 감지하는 것 같습니다.

Fully qualified name of the JDBC driver. Auto-detected based on the URL by default.

 

*stackoverflow.com/a/33324144/7225691

*github.com/spring-projects/spring-boot/blob/v1.3.0.M2/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/jdbc/DataSourceProperties.java

*gmlwjd9405.github.io/2018/05/15/setting-for-db-programming.html

spring.datasource.url: "jdbc:postgresql://database:5432/my_local"

데이터베이스의 JDBC url을 의미합니다.

사용하는 DB에 따라 포멧이 약간씩 다르니 본인의 DB에 맞는 값을 잘 사용하면 됩니다.

 

*howtodoinjava.com/spring-boot2/datasource-configuration/

spring.datasource.username: "postgres"

database의 로그인 username

spring.datasource.password: "{cipher}4788dfe1ccbe6485934aec2ffeddb06163ea3d616df5fd75be96aadd4df1da91"

database의 로그인 password

 

spring.datasource.testWhileIdle: "true"

스프링 1.4 버전 부터는 spring.datasource.tomcat.testwhileidle 로 쓰이는 것 같습니다.

 

*d2.naver.com/helloworld/5102792(꼭 읽어볼 것!)

*preamtree.tistory.com/78

 

spring.datasource.validationQuery: "SELECT 1"

JDBC 커넥션의 유효성을 확인할 때 사용하는 쿼리문

 

spring.jpa.properties.hibernate.dialect: "org.hibernate.dialect.PostgreSQLDialect"

ORM은 객체 맵핑을 통해 자동으로 SQL 쿼리문을 작성합니다. 그러나 DB마다 쿼리가 다를 수도 있기 때문에 위의 설정으로 인해 dialect를 설정합니다. 그런데 보통 자동으로 설정된 값을 사용하면 되는 것 같습니다.

*2dongdong.tistory.com/66(글 좋음)

*medium.com/@sindepal/jpa-custom-dialect-%EB%B0%A9%EC%96%B8-spring-boot-f7c71f2d7d72

 

spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation: "true"

아래 링크 참고

*n1tjrgns.tistory.com/m/272?category=898948

*medium.com/msolo021015/%EC%8A%A4%ED%94%84%EB%A7%81-%EB%B6%80%ED%8A%B8%EB%A1%9C-%EC%8B%9C%EC%9E%91%ED%95%98%EB%8A%94-%ED%85%8C%EC%8A%A4%ED%8A%B8-jpa-part-2-ef3c302cff52

*stackoverflow.com/questions/43905119/postgres-error-method-org-postgresql-jdbc-pgconnection-createclob-is-not-imple?rq=1&utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa

spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults: "false"

true(기본값)

This setting is used to control whether we should consult the JDBC metadata to determine certain Settings default values when the database may not be available (mainly in tools usage).

*n1tjrgns.tistory.com/m/272?category=898948

*docs.jboss.org/hibernate/orm/5.4/userguide/html_single/Hibernate_User_Guide.html#configurations-internal

spring.jpa.hibernate.ddl-auto: "create-drop"

아래 링크 참고

 

*pravusid.kr/java/2018/10/10/spring-database-initialization.html

signing.key: "345345fsdfsf5345"

 

 

 

 

참고

spring.io/guides/gs/accessing-data-mysql/

 

Accessing data with MySQL

this guide is designed to get you productive as quickly as possible and using the latest Spring project releases and techniques as recommended by the Spring team

spring.io

docs.spring.io/spring-boot/docs/2.1.18.RELEASE/reference/html/howto-data-access.html

 

85. Data Access

Spring Boot includes a number of starters for working with data sources. This section answers questions related to doing so. 85.1 Configure a Custom DataSource To configure your own DataSource, define a @Bean of that type in your configuration. Spring Boo

docs.spring.io

docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html

 

Common Application properties

Various properties can be specified inside your application.properties file, inside your application.yml file, or as command line switches. This appendix provides a list of common Spring Boot properties and references to the underlying classes that consume

docs.spring.io

docs.spring.io/spring-boot/docs/2.1.x/reference/html/howto-database-initialization.html

 

86. Database Initialization

An SQL database can be initialized in different ways depending on what your stack is. Of course, you can also do it manually, provided the database is a separate process. It is recommended to use a single mechanism for schema generation. 86.2 Initialize a

docs.spring.io

stackoverflow.com/questions/30118683/how-to-log-sql-statements-in-spring-boot

 

How to log SQL statements in Spring Boot?

I want to log SQL statements in a file. I have the following properties in application.properties spring.datasource.url=... spring.datasource.username=user spring.datasource.password=1234 spring.

stackoverflow.com

m.blog.naver.com/kh2un/222008545174

 

Spring + JPA + Hibernate 로그 설정

Spring + JPA + Hibernate 환경 설정 ​​application.properties - hibernate가 만들어준 SQL (pr...

blog.naver.com

 

작성자

Posted by 드리머즈

관련 글

댓글 영역