사용자 도구

사이트 도구


springframework:bean

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
다음 판 양쪽 다음 판
springframework:bean [2015/11/18 14:53]
kwon37xi [설정에 등록]
springframework:bean [2019/11/27 16:58]
kwon37xi [SmartLifeCycle]
줄 15: 줄 15:
   * [[springframework:javaconfig|Springframework Java Config]] 사용시에는 static으로 등록해야한다.   * [[springframework:javaconfig|Springframework Java Config]] 사용시에는 static으로 등록해야한다.
  
 +==== SmartLifeCycle ====
 +  * [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/context/SmartLifecycle.html|SmartLifecycle]]
 +  * [[http://selvakumaresra.herokuapp.com/spring-smartlifecycle-smart-shutdown-sequence-for-java-service/|Spring SmartLifeCycle]]
 +  * ''getPhase()'' 에서 ''Integer.MAX_VALUE''를 리턴하면 제일 늦게 생성되고, 제일 먼저 파괴 된다. 이 최우선 파괴 시점에 다른 Bean의 파괴 타이밍을 조정해준다.
 +  * ''SmartLifeCycle'' 안에서 다른 Bean 을 destroy 하려면, 그냥 하면 안되고 ''BeanFactoryAware'' 인터페이스를 구현하여 ''DefaultSingletonBeanRegistry'' 를 주입받은뒤, [[https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/beans/factory/support/DefaultSingletonBeanRegistry.html#destroySingleton-java.lang.String-|DefaultSingletonBeanRegistry.destroySingleton(beanName)]]을 사용해야한다. 그래야 Bean destroy 후에 해당 빈을 ApplicationContext 에서 제거해주어 중복 destroy 를 막아준다.
 +  * 입력받는 역할을 하는것(MQ Listener 등)을 먼저 종료시켜줘야 더이상 입력이 없는 상태에서 Gracefull 한 종료가 가능해진다.
 ===== Dynamic Bean Definition - 동적 Bean 생성 ===== ===== Dynamic Bean Definition - 동적 Bean 생성 =====
 +  * [[http://www.tutorialspoint.com/spring/spring_bean_definition.htm|Spring Bean Definition]]
 +
 ==== 구현 ==== ==== 구현 ====
   * [[http://docs.spring.io/autorepo/docs/spring-framework/current//javadoc-api/org/springframework/beans/factory/support/BeanDefinitionRegistryPostProcessor.html|BeanDefinitionRegistryPostProcessor]]를 구현한다.<code java>   * [[http://docs.spring.io/autorepo/docs/spring-framework/current//javadoc-api/org/springframework/beans/factory/support/BeanDefinitionRegistryPostProcessor.html|BeanDefinitionRegistryPostProcessor]]를 구현한다.<code java>
줄 46: 줄 54:
   * 해당 구현체 자체를 ''@Configuration''으로 지정하거나 그냥 ''@Bean''으로 생성하는 것은 작동하지 않는다.   * 해당 구현체 자체를 ''@Configuration''으로 지정하거나 그냥 ''@Bean''으로 생성하는 것은 작동하지 않는다.
   * [[http://docs.spring.io/autorepo/docs/spring-framework/current//javadoc-api/org/springframework/context/ApplicationContextInitializer.html|ApplicationContextInitializer]] 안에서 [[http://docs.spring.io/autorepo/docs/spring-framework/current//javadoc-api/org/springframework/context/ConfigurableApplicationContext.html#addBeanFactoryPostProcessor-org.springframework.beans.factory.config.BeanFactoryPostProcessor-|applicationContext.addBeanFactoryPostProcessor]]로 등록한다.   * [[http://docs.spring.io/autorepo/docs/spring-framework/current//javadoc-api/org/springframework/context/ApplicationContextInitializer.html|ApplicationContextInitializer]] 안에서 [[http://docs.spring.io/autorepo/docs/spring-framework/current//javadoc-api/org/springframework/context/ConfigurableApplicationContext.html#addBeanFactoryPostProcessor-org.springframework.beans.factory.config.BeanFactoryPostProcessor-|applicationContext.addBeanFactoryPostProcessor]]로 등록한다.
 +
 +
  
 ==== 참조 ==== ==== 참조 ====
   * [[http://blog.jdriven.com/2015/04/spicy-spring-dynamically-create-your-own-beandefinition/|Spicy Spring : Dynamically create your own BeanDefinition]]   * [[http://blog.jdriven.com/2015/04/spicy-spring-dynamically-create-your-own-beandefinition/|Spicy Spring : Dynamically create your own BeanDefinition]]
   * [[https://dzone.com/articles/how-create-your-own-dynamic|How to Create Your Own 'Dynamic' Bean Definitions in Spring]]   * [[https://dzone.com/articles/how-create-your-own-dynamic|How to Create Your Own 'Dynamic' Bean Definitions in Spring]]
springframework/bean.txt · 마지막으로 수정됨: 2021/11/12 13:05 저자 kwon37xi