[3주차] 관심사 분리 1 - 신재희#74
Open
yuntasha wants to merge 24 commits into
Open
Conversation
[3주차] 관심사 분리 1 - 신재희
jude-loopers
reviewed
May 6, 2026
jude-loopers
left a comment
Collaborator
There was a problem hiding this comment.
재희님 고생하셨습니다~
궁금한점 몇가지를 남겨봤어요
Comment on lines
+29
to
+31
| public Set<Field> scanField(final Class<?> clazz) { | ||
| return Arrays.stream(clazz.getDeclaredFields()).filter(field -> Objects.nonNull(field.getDeclaredAnnotation(Autowired.class))).collect(Collectors.toSet()); | ||
| } |
Collaborator
There was a problem hiding this comment.
이 메서드가 BeanSacnner 역할에 알맞을까요?
| private static BeanStorage instance; | ||
|
|
||
| private final List<Object> beans; | ||
| private final BeanScanner bc = new BeanScanner("com.diy.app"); |
Collaborator
There was a problem hiding this comment.
음.. 이걸 하드코딩 해도 괜찮을까요?
|
|
||
| public UrlControllerMapper() { | ||
| uriToController.put("/lectures", new LectureController(LectureService.getInstance())); | ||
| uriToController.put("/lectures", BeanStorage.getInstance().getBeans(LectureController.class).getFirst()); |
Collaborator
There was a problem hiding this comment.
오호 BeanStorage 를 싱글톤으로 활용해서 controller 매핑을 하는군요 ㅎㅎ
Comment on lines
+68
to
+86
| public static void setFields(Object target, List<Object> nowBeanList, Map<Class<?>, Set<Field>> classToFields) { | ||
| for (Field field : classToFields.get(target.getClass())) { | ||
| Object fieldTarget = null; | ||
| for (Object targetBean : nowBeanList) { | ||
| if (!field.getType().isInstance(targetBean)) continue; | ||
| if (Objects.nonNull(fieldTarget)) throw new IllegalArgumentException("2개 이상의 빈이 존재 : " + field.getType().getName()); | ||
| fieldTarget = targetBean; | ||
| } | ||
| if (Objects.isNull(fieldTarget)) throw new IllegalArgumentException("존재하지 않는 빈 : " + field.getType().getName()); | ||
| try { | ||
| field.setAccessible(true); | ||
| field.set(target, fieldTarget); | ||
| } catch (IllegalAccessException e) { | ||
| throw new RuntimeException(e); | ||
| } finally { | ||
| field.setAccessible(false); | ||
| } | ||
| } | ||
| } |
Collaborator
There was a problem hiding this comment.
음 이 메서드에 대해서는 궁금한게 많아요.
왜 static 일까요? 그리고 이 메서드는 왜 필요할까요?
♻️ Autowired 요구사항에 맞게 변경
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
요구사항
빈 생성
빈 주입
나만의 추가 요구사항
AOP 실습
test로 시작하는 메소드 실행하기
methods 값 확인
결과
toString()이라 내가 사용할만한 값이 아니다.
getName을 발견
getName()값 확인
결과
내가 원하는 결과가 나왔다.
필터링
결과
인스턴스 만들기
}
testGetName
test : null
testGetPrice
test : 0
@PrintView 애노테이션 메소드 실행
AOP Lecture 요구사항
1. 생성자 찾기
결과
2. Lecture 인스턴스 동적 생성
3. private 메서드 찾기
결과
6. @MethodOrder 애너테이션 정보 조회
결과
빈 조회 및 필드 조회
이슈 및 생각 정리
위상 정렬을 통해 순서를 찾은 이유
instanceof가 동작하지 않음
자바 리플렉션의 경우 런타임 시점에서 진행되기 때문에 컴파일 시점에 적용되는 instanceof를 사용할 수 없습니다.
따라서 아래 Class.isInstance(Object) 메서드를 사용하여 처리하였습니다.