How do you configure a DataSource in Spring?
Dependency
Maven
<!-- pom.xml -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.200</version>
<scope>runtime</scope>
</dependency>
Gradle
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'com.h2database:h2'
}
configuration properties
application.yml
spring:
datasource:
url: jdbc:h2:mem:mydb
username: sa
password: temppassword
driverClassName: org.h2.Driver
jpa:
spring.jpa.database-platform: org.hibernate.dialect.H2Dialect
application.properties
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.username=sa
spring.datasource.password=temppassword
spring.datasource.driverClassName=org.h2.Driver
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
'Certification > Spring(2V0-72.22, SCP)' 카테고리의 다른 글
What are the advantages of using Spring Boot? (0) | 2021.11.08 |
---|---|
What is Spring Boot? (0) | 2021.11.07 |
What is the difference between checked and unchecked exceptions? (0) | 2021.11.07 |
What is the concept of AOP? Which problem does it solve? What is a cross cutting concern? (0) | 2021.11.06 |
What is dependency injection and what are the advantages of using it? (0) | 2021.11.03 |