-
Notifications
You must be signed in to change notification settings - Fork 5
[spring-core-2] ivy.lee(이다예) 과제 제출합니다. #44
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
base: ivy/spring-core-2
Are you sure you want to change the base?
Changes from all commits
0ba7b98
257d8a7
18c9ca4
f36b2c2
cf8ace6
24ecb3e
1e73430
e66249c
e1c91a8
ae95b61
7b202dd
1e057c3
0cb9f37
ae61c19
7553778
16fdf85
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 |
|---|---|---|
| @@ -1,10 +1,11 @@ | ||
| package cholog.scan; | ||
|
|
||
| import org.springframework.context.annotation.ComponentScan; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Configuration | ||
| /* | ||
| ComponentScan에 대해 학습하고, ComponenetScanBean을 Bean으로 등록하기 | ||
| */ | ||
| @ComponentScan(basePackages = "cholog.scan") | ||
| public class ContextConfiguration { | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,16 +3,21 @@ | |
| import cholog.profile.InmemoryMessageRepository; | ||
| import cholog.profile.JdbcMessageRepository; | ||
| import cholog.profile.MessageRepository; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.Profile; | ||
|
|
||
| // TODO: Java-based Configuration을 하기 위한 클래스로 지정하기 | ||
| @Configuration | ||
| public class ProfileConfig { | ||
|
|
||
| // TODO: dev 프로파일일 때만 InmemoryMessageRepository 빈이 등록되도록 설정하기 | ||
| @Bean("dataSource") | ||
|
Member
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. "dataSource"가 어떤 걸 의미하는지 궁금합니다! 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. Readme 예시에서 이런 식으로 나와 있어 저도 꼭 적어야 하는건가? 하는 생각이었지만 찾아본 내용을 공유해드립니다! @bean 어노테이션 괄호 안의
Member
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. 오 그렇군요! 감사합니다!! |
||
| @Profile("dev") | ||
| public MessageRepository inMemoryMessageRepository() { | ||
| return new InmemoryMessageRepository(); | ||
| } | ||
|
|
||
| // TODO: prod 프로파일일 때만 InmemoryMessageRepository 빈이 등록되도록 설정하기 | ||
| @Bean("dataSource") | ||
| @Profile("prod") | ||
| public MessageRepository jdbcMessageRepository() { | ||
| return new JdbcMessageRepository(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,18 @@ | ||
| package cholog.property.config; | ||
|
|
||
| import cholog.property.JwtTokenKeyProvider; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| // TODO: Java-based Configuration을 하기 위한 클래스로 지정하기 | ||
|
|
||
| @Configuration | ||
| public class AuthConfig { | ||
| // TODO: application.properties의 security.jwt.token.secret-key 값을 활용하여 JwtTokenKeyProvider를 빈으로 등록하기 | ||
| @Value("${security.jwt.token.secret-key}") | ||
|
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. 의존성 주입 부분에서 메서드 주입 방식이 아닌 필드 주입 방식을 쓰신 것 같은데 메서드 파라미터로 직접 값을 주입하는 방식이 코드의 의존성이 메서드 시그니처에 명시적으로 드러나게 되기 때문에 가독성과 의존성 관리를 위해서 메서드 주입 방식을 쓰시는 것도 좋을 듯합니다! |
||
| private String secretKey; | ||
|
|
||
| @Bean | ||
| public JwtTokenKeyProvider jwtTokenKeyProvider() { | ||
| return new JwtTokenKeyProvider(""); | ||
| return new JwtTokenKeyProvider(secretKey); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,10 +2,14 @@ | |
|
|
||
| import cholog.property.GoogleDriveRestClient; | ||
| import cholog.property.GoogleMapsRestClient; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.context.annotation.PropertySource; | ||
| import org.springframework.core.env.Environment; | ||
|
|
||
| // TODO: Java-based Configuration을 하기 위한 클래스로 지정하기 | ||
| // TODO: ext-api.properties 파일을 활용하기 위한 설정 추가하기 | ||
| @Configuration | ||
| @PropertySource("classpath:ext-api.properties") | ||
| public class PropertySourceConfig { | ||
|
|
||
| private final Environment env; | ||
|
|
@@ -14,15 +18,17 @@ public PropertySourceConfig(Environment env) { | |
| this.env = env; | ||
| } | ||
|
|
||
| // TODO: ext-api.properties의 google.api.endpoint 값을 Environment를 사용해서 가져오기 | ||
| // TODO: 위 endpoint 값을 사용하여 GoogleMapsRestClient를 빈으로 등록하기 | ||
| @Bean | ||
| public GoogleMapsRestClient googleMapsRestClient() { | ||
| return new GoogleMapsRestClient(""); | ||
| String endpoint = env.getProperty("google.api.endpoint"); | ||
| return new GoogleMapsRestClient(endpoint); | ||
| } | ||
|
|
||
| // TODO: ext-api.properties의 google.api.endpoint 값을 어노테이션을 사용해서 가져오기 | ||
| // TODO: 위 endpoint 값을 사용하여 GoogleMapsRestClient를 빈으로 등록하기 | ||
| @Value("${google.api.endpoint}") | ||
| private String googleApiEndpoint; | ||
|
Comment on lines
+27
to
+28
Member
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. 해당 방법도 좋고, parameter 안에 @value를 사용하는 법도 있습니다! |
||
|
|
||
| @Bean | ||
| public GoogleDriveRestClient googleDriveRestClient() { | ||
| return new GoogleDriveRestClient(""); | ||
| return new GoogleDriveRestClient(googleApiEndpoint); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,33 @@ | ||
| package cholog; | ||
|
|
||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.bind.annotation.ResponseBody; | ||
|
|
||
| @Controller | ||
| public class MemberController { | ||
|
|
||
| public String world() { | ||
| @GetMapping("/hello") | ||
| public String world(@RequestParam(name = "name", required = false) String name, Model model) { | ||
| // TODO: /hello 요청 시 resources/templates/static.html 페이지가 응답할 수 있도록 설정하세요. | ||
| // TODO: 쿼리 파라미터로 name 요청이 들어왔을 때 해당 값을 hello.html에서 사용할 수 있도록 하세요. | ||
| return null; | ||
| if (name == null){ | ||
| // 쿼리 파라미터가 없는 경우 | ||
| return "static"; | ||
| } else { | ||
| // 쿼리 파라미터가 있는 경우. | ||
| model.addAttribute("name", name); | ||
| return "hello"; | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
||
| @GetMapping("/json") | ||
| @ResponseBody | ||
| public Person json() { | ||
| // TODO: /json 요청 시 {"name": "brown", "age": 20} 데이터를 응답할 수 있도록 설정하세요. | ||
| return null; | ||
| return new Person("brown", 20); | ||
| } | ||
| } |
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.
SpringCoreApplication.java에 @SpringBootApplication이 @componentscan을 들고 있어서,
여기엔 @componentscan이 필요 없습니다!