Spring Framework

    [Spring] AppliacationEventPublisher

    ApplicationEventPublisher 이벤트 프로그래밍에 필요한 인터페이스 제공 옵저버 패턴 구현체 ApplicationContext extends ApplicationEventPublisher publishEvent(ApplicationEvent event) 이벤트 만들기 ApplicationEvent 상승 스프링4.2 부터는 이 클래스를 상속받지 않아도 이벤트로 사용할 수 있다. 이벤트 발생 시키는 방법 ApplicationEventPublisher.publishEvenr(); 이벤트 처리하는 방법 ApplicationListener를 구현한 클래스를 만들어서 빈으로 등록하기 스프링4.2 부터는 @EventListener를 사용해서 빈의 메소드에 사용할 수 있다. 기본적으로는 synchron..

    [Spring] MessageSource

    [Spring] MessageSource

    MessageSource 국제화(i18n) 기능을 제공하는 인터페이스 ApplicationContext extends MessageSource getMessage(String code, Object[] args, String, default, Locale, loc) ... 스프링 부트를 사용한다면 별다른 설정 필요없이 messages.properties를 사용할 수 있다. messages.properties messages_ko_kr.properties ... 릴로딩 기능이 있는 메시지 소스 사용하기

    [Spring] Environment

    Environment 프로파일과 프로퍼티를 다루는 인터페이스 ApplicationContext extends EnvironmentCapable getEnvironment() 프로파일 빈들의 그룹 Environment의 역할은 활성화할 프로파일 확인 및 설정 프로파일 유즈케이스 이 빈은 모니터링 용도이기에 테스트할 때는 필요가 없고 배포할 떄만 등록이 되면 좋겠다. 프로파일 정의하기 클래스에 정의 @Configuration @Profile("test") @Component @Profile("test") 메소드에 정의 @Bean @Profile("test") 프로파일 설정하기 -Dspring.profiles.avtive="test" @ActiveProfiles 프로파일 표현식 ! (not) & (and) |..

    [Spring] 빈의 스코프

    스코프(Scope) 싱글톤 프로토타입 Request Session WebSocket ... 프로토타입 빈이 싱글톤 빈을 참조하는데 문제 없다. 싱글톤 빈이 프로토타입 빈을 참조하면 같은 객체를 참조한다. 즉 프로토타입 빈이 업데이트 되지 않는다. 업데이트를 하려면 scoped-proxy, Object-Provider, Provider(표준)을 사용해야한다. 싱글톤 객체 사용시 주의할 점 프로퍼티가 공유된다. ApplicationContext 초기 구동시 인스턴스가 생성된다.