-
Notifications
You must be signed in to change notification settings - Fork 0
[Step3] 데이터베이스를 교체한다. #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d6837e7
f6f0082
7b3b80a
c5490ac
9b33c1e
43da321
21c72f1
8538aea
00b4fb1
ab6753d
623ac9a
73ec54e
f924765
615d015
8c67fa8
9e0b32b
20d813d
383b6d9
b2b7f53
71f567b
319fb6b
434d7b5
b0a19e1
c7cd900
9a9132c
d8898ab
ba608fc
fb4183b
08c182b
fb4b4ba
7824175
25f932e
e211aee
222b95b
a1daa1f
ce88f98
50e3d8a
171756c
506f636
5613715
414e8a2
dd213c8
b93ca46
c26c263
70c9a64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,3 +34,4 @@ out/ | |
|
|
||
| ### VS Code ### | ||
| .vscode/ | ||
| *.yml | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| ## ⛺️ Application 모듈 | ||
|
|
||
| Application 모듈. | ||
|
|
||
| <br/><br/><br/> | ||
|
|
||
| ## 👪 패키지 간 의존관계 | ||
|
|
||
| Application 모듈은 Mvc, Jdbc 모듈에 의존합니다. | ||
|
|
||
| | Application Module | Mvc Module | Jdbc Module | | ||
| |:------------------:|:----------:|:-----------:| | ||
| | - | O | O | | ||
|
|
||
| - Application: 애플리케이션 모듈 <br/> | ||
| - Mvc: 스프링 Mvc 모듈 <br/> | ||
| - Jdbc: 데이터베이스 접근 모듈 <br/> | ||
|
|
||
| <br/> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,10 @@ plugins { | |
|
|
||
| dependencies { | ||
| implementation(project(":mvc")) | ||
| implementation(project(":jdbc")) | ||
|
|
||
| implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.13.1") | ||
| runtimeOnly("com.mysql:mysql-connector-j:8.1.0") | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 추가하신 각각의 의존성에 대해서 설명해주세요!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 다시 생각해보니 jackson-databind는 사용할 필요가 없겠네요. 👀 제외하겠습니다. |
||
|
|
||
| tasks.named("test") { | ||
|
|
@@ -68,3 +72,25 @@ sonarqube { | |
| property("sonar.coverage.jacoco.xmlReportPaths", "${buildDir}/jacoco/index.xml") | ||
| } | ||
| } | ||
|
|
||
| task downloadYml { | ||
| doLast { | ||
| def url = new URL(System.getenv("YML_URL")) | ||
| def connection = url.openConnection() | ||
|
|
||
| def file = new File(projectDir, "./src/main/resources/application.yml") | ||
| if (!file.parentFile.exists()) { | ||
| file.parentFile.mkdirs() | ||
| } | ||
|
|
||
| connection.inputStream.withStream { inputStream -> | ||
| file.withOutputStream { outputStream -> | ||
| inputStream.transferTo(outputStream) | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks.named("downloadYml") { | ||
| dependsOn downloadYml | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package project.server.app.common.configuration; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import static com.fasterxml.jackson.databind.PropertyNamingStrategies.KEBAB_CASE; | ||
| import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import project.server.jdbc.core.ConfigMap; | ||
|
|
||
| public class ConfigMapLoader { | ||
|
|
||
| public ConfigMap getConfigMap() throws IOException { | ||
| return loadConfig("application.yml"); | ||
| } | ||
|
|
||
| public ConfigMap loadConfig(String resourcePath) throws IOException { | ||
| InputStream inputStream = getInputStream(resourcePath); | ||
| if (inputStream == null) { | ||
| throw new IOException("Resource not found: " + resourcePath); | ||
| } | ||
|
|
||
| ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); | ||
| mapper.setPropertyNamingStrategy(KEBAB_CASE); | ||
| return mapper.readValue(inputStream, ConfigMap.class); | ||
| } | ||
|
|
||
| private InputStream getInputStream(String resourcePath) { | ||
| return ConfigMapLoader.class.getClassLoader() | ||
| .getResourceAsStream(resourcePath); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| package project.server.app.common.configuration; | ||
|
|
||
| import java.io.IOException; | ||
| import project.server.jdbc.core.ConfigMap; | ||
| import project.server.jdbc.core.DriverManager; | ||
| import project.server.jdbc.core.jdbc.JdbcTemplate; | ||
| import project.server.jdbc.core.transaction.JdbcTransactionManager; | ||
| import project.server.jdbc.core.transaction.PlatformTransactionManager; | ||
| import project.server.mvc.springframework.annotation.Bean; | ||
| import project.server.mvc.springframework.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class DatabaseConfiguration { | ||
|
|
||
| @Bean | ||
| public ConfigMapLoader configMapLoader() { | ||
| return new ConfigMapLoader(); | ||
| } | ||
|
|
||
| @Bean | ||
| public DriverManager driverManager() throws IOException { | ||
| ConfigMap configMap = configMapLoader().getConfigMap(); | ||
| return new DriverManager(configMap); | ||
| } | ||
|
|
||
| @Bean | ||
| public PlatformTransactionManager transactionManager() throws IOException { | ||
| return new JdbcTransactionManager(driverManager().getDataSource()); | ||
| } | ||
|
|
||
| @Bean | ||
| public JdbcTemplate jdbcTemplate() throws IOException { | ||
| return new JdbcTemplate(driverManager().getDataSource()); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package project.server.app.common.utils; | ||
|
|
||
| import project.server.mvc.springframework.annotation.Configuration; | ||
|
|
||
| @Configuration | ||
| public class JdbcConfiguration { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| package project.server.app.core.web.user.application; | ||
|
|
||
| import project.server.app.core.domain.user.User; | ||
|
|
||
| public interface UserSaveUseCase { | ||
| User save(User user); | ||
| Long save(String username, String password); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.yml을 .gitignore에 추가해놓은 이유가 있나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
외부에 config 서버를 두고 설정 파일을 다운받아 사용할 예정이기에 yml 파일이 노출될 필요가 없기 때문입니다.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
프로필을 분리해서 관리하는� 방식은 어떻게 생각하시나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
그것도 괜찮은 방식이죠. 👍 기존에 스프링을 사용할 때, 말씀하신 개발 환경에 따른 분리를 하기 때문에 이번 미션에선 다른 방법을 채택했습니다.