-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
230 additions
and
23 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
## 💡 개요 | ||
- Jira | ||
## 🤔배경 | ||
|
||
### 📄 작업 사항 | ||
|
||
|
||
|
||
### ✔️ 코드 리뷰 반영 사항 | ||
|
||
|
||
### 📚 레퍼런스 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,7 @@ out/ | |
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
.vscode/ | ||
|
||
### ENV ### | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: '3' | ||
services: | ||
mysql: | ||
image: mysql:8 | ||
ports: | ||
- 3306:3306 | ||
container_name: mysql | ||
environment: | ||
MYSQL_DATABASE: moneymong | ||
MYSQL_ROOT_PASSWORD: 1234 | ||
volumes: | ||
- ./mysqldata:/var/lib/mysql | ||
restart: always |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.moneymong.api.config; | ||
|
||
import com.zaxxer.hikari.HikariDataSource; | ||
import jakarta.persistence.EntityManagerFactory; | ||
import javax.sql.DataSource; | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.DependsOn; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.data.jpa.repository.config.EnableJpaRepositories; | ||
import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy; | ||
import org.springframework.orm.jpa.JpaTransactionManager; | ||
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
|
||
@EnableJpaRepositories( | ||
basePackages = { | ||
"com.moneymong.api" | ||
}, | ||
entityManagerFactoryRef = "moneyMongEntityManagerFactory", | ||
transactionManagerRef = "moneyMongTransactionManager" | ||
) | ||
@Configuration(proxyBeanMethods = false) | ||
public class JPAConfig { | ||
@Bean | ||
@ConfigurationProperties(prefix = "datasource.db") | ||
public DataSource moneyMongDataSource() { | ||
return new HikariDataSource(); | ||
} | ||
|
||
@Primary | ||
@Bean | ||
@DependsOn("moneyMongDataSource") | ||
public DataSource moneyMongLazyDataSource( | ||
@Qualifier("moneyMongDataSource") DataSource dbDataSource | ||
) { | ||
return new LazyConnectionDataSourceProxy(dbDataSource); | ||
} | ||
|
||
@Primary | ||
@Bean | ||
public LocalContainerEntityManagerFactoryBean moneyMongEntityManagerFactory( | ||
EntityManagerFactoryBuilder entityManagerFactoryBuilder, | ||
@Qualifier("moneyMongLazyDataSource") DataSource lazyDataSource | ||
) { | ||
return entityManagerFactoryBuilder | ||
.dataSource(lazyDataSource) | ||
.packages("com.moneymong.api.domain") | ||
.persistenceUnit("moneymong") | ||
.build(); | ||
} | ||
|
||
@Bean | ||
public PlatformTransactionManager moneyMongTransactionManager( | ||
@Qualifier("moneyMongEntityManagerFactory") EntityManagerFactory moneyMongEntityManagerFactory | ||
) { | ||
return new JpaTransactionManager(moneyMongEntityManagerFactory); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/com/moneymong/api/controller/TestController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.moneymong.api.controller; | ||
|
||
import com.moneymong.api.service.TestService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RequiredArgsConstructor | ||
@RestController | ||
public class TestController { | ||
private final TestService testService; | ||
|
||
@GetMapping("/test/create") | ||
public void create( | ||
@RequestParam("name") String name | ||
) { | ||
testService.create(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.moneymong.api.domain; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
@Table(name = "test") | ||
public class TestEntity { | ||
@Id | ||
@Column(name = "id") | ||
Long id; | ||
|
||
@Column(name = "name") | ||
String name; | ||
|
||
|
||
public static TestEntity createNew(String name) { | ||
return TestEntity.builder() | ||
.id(1L) | ||
.name(name) | ||
.build(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/com/moneymong/api/repository/TestRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.moneymong.api.repository; | ||
|
||
import com.moneymong.api.domain.TestEntity; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface TestRepository extends JpaRepository<TestEntity, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.moneymong.api.service; | ||
|
||
import com.moneymong.api.domain.TestEntity; | ||
import com.moneymong.api.repository.TestRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class TestService { | ||
private final TestRepository testRepository; | ||
|
||
@Transactional | ||
public TestEntity create(String name) { | ||
TestEntity testEntity = TestEntity.createNew(name); | ||
return testRepository.save(testEntity); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,68 @@ | ||
spring: | ||
config: | ||
import: optional:file:.env[.properties] | ||
|
||
server: | ||
port: ${SERVER_PORT} | ||
port: 8080 | ||
shutdown: graceful | ||
|
||
spring: | ||
profiles: | ||
active: local | ||
|
||
jpa: | ||
open-in-view: false | ||
show-sql: true | ||
properties: | ||
format_sql: true | ||
hibernate: | ||
ddl-auto: create | ||
|
||
|
||
# actuator 관리 | ||
management: | ||
endpoints: | ||
web: | ||
base-path: / | ||
exposure: | ||
include: health | ||
|
||
# db 설정 | ||
datasource: | ||
db: | ||
pool-name: moneymong | ||
jdbc-url: jdbc:mysql://localhost:3306/moneymong?useSSL=false&&allowPublicKeyRetrieval=true | ||
username: root | ||
password: 1234 | ||
driver-class-name: com.mysql.cj.jdbc.Driver | ||
maximum-pool-size: 5 | ||
connection-timeout: 3000 | ||
cache-prep-stmts: true | ||
prep-stmt-cache-size: 250 | ||
prep-stmt-cache-sql-limit: 2048 | ||
use-server-prep-stmts: true | ||
use-local-session-state: true | ||
cache-result-set-metadata: true | ||
maintain-time-stats: false | ||
leak-detection-threshold: 5000 | ||
autocommit: false | ||
connection-init-sql: "SET NAMES 'utf8mb4'" | ||
read-only: false | ||
data-source-properties: | ||
useCursors: false | ||
sendStringParametersAsUnicode: false | ||
characterEncoding: utf8 | ||
zeroDateTimeBehavior: convertToNull | ||
useSSL: false | ||
autoReconnect: true | ||
autoReconnectForPools: true | ||
usePipelineAuth: false | ||
useBatchMultiSend: false | ||
|
||
--- | ||
spring: | ||
config: | ||
activate: | ||
on-profile: local | ||
|
||
--- | ||
spring: | ||
config: | ||
activate: | ||
on-profile: dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters