# Section 12.
(1) 메타데이터 위치나 이름을 설정할 수 있도록 개선하기 (2) 빈 생명주기 콜백 인터페이스로 메타데이터 검증하기
* 빈 생명주기 관여하기
- 스프링 컨테이너는 빈의 생성부터 초기화, 소멸까지 생명주기에 관여할 수 있는 확 장지점을 제공한다.
- 빈 객체에 콜백 인터페이스를 구현해 빈 생명주기에 관여할 수 있다.
- 자바 플랫폼에서 자주 사용되는 애노테이션을 표준화한 JSR-250 을 지원한다. - 빈 등록시 초기화 또는 소멸시 사용될 메서드를 등록할 수 있다.
(3) 메타데이터 검증 로직 추상화하기
추상 클래스인 AbstractFileSystemMovieReader 를 만들어 낸 이유 = 이 코드가 XmlMovieReader 에도 그대로 재사용 될 것이기 때문
package moviebuddy;
/**
* @author springrunner.kr@gmail.com */
@SuppressWarnings("serial")
public class ApplicationException extends RuntimeException {
public ApplicationException(String message) { super(message);
}
public ApplicationException(String message, Throwable cause) { super(message, cause);
}
public static class CommandNotFoundException extends ApplicationException {
public CommandNotFoundException() { super("command not found.");
} }
public static class UndefinedCommandActionException ApplicationException {
public UndefinedCommandActionException() { super("command action is undefined.");
} }
public static class InvalidCommandArgumentsException extends ApplicationException {
public InvalidCommandArgumentsException() { super("input error, please try again!");
}
public InvalidCommandArgumentsException(String message) { super(message);
}
public InvalidCommandArgumentsException(Throwable cause) { super(String.format("%s: %s", cause.getClass().getSimpleName(),
cause.getMessage()), cause); }
} }
// 이 클래스는 영화친구 애플리케이션이 동작하는 과정에서 문제가 있을 때, 즉 오류가 있을 때 이 오류를 예외 객체로 잡아서 외부에 전파하기 위해서 사용이 된다.
// 메시지를 담을 수도 있고, 메시지와 함께 그 상위에 발생된 예외를 담을 수 있도록 구성이 되어 있다.
'CNU_SW_모각코' 카테고리의 다른 글
16주차 모각코 학습 결과(22.10.18 14:00 ~ 17:00) (0) | 2022.10.25 |
---|---|
16주차 모각코 학습 목표(22.10.18 14:00 ~ 17:00) (0) | 2022.10.25 |
15주차 모각코 학습 목표(22.10.12 14:00 ~ 17:00) (0) | 2022.10.25 |
14주차 모각코 학습 결과(22.10.05 14:00 ~ 17:00) (0) | 2022.10.06 |
14주차 모각코 학습 목표(22.10.05 14:00 ~ 17:00) (0) | 2022.10.06 |