사용자 도구

사이트 도구


springframework:scope

차이

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

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
마지막 판 양쪽 다음 판
springframework:scope [2014/05/08 19:19]
kwon37xi
springframework:scope [2018/09/17 18:03]
kwon37xi
줄 1: 줄 1:
 ====== Spring Bean Scope ====== ====== Spring Bean Scope ======
 +  * [[https://www.baeldung.com/spring-lookup|@Lookup Annotation in Spring]]
 +
 ===== prototype ===== ===== prototype =====
   * 매번 객체 새로 생성할 필요가 있을 경우 사용한다.   * 매번 객체 새로 생성할 필요가 있을 경우 사용한다.
-  * [[http://docs.oracle.com/javaee/7/api/javax/annotation/PreDestroy.html|@PreDestroy]] 애노테이션이 작동하지 않는다. 그 외의 다른 스코프에서는 작동한다. [[http://stackoverflow.com/questions/22848563/predestroy-on-session-scoped-spring-mvc-controllers|참조 @PreDestroy on session scoped ...]]+  * [[http://docs.oracle.com/javaee/7/api/javax/annotation/PreDestroy.html|@PreDestroy]] 애노테이션이 작동하지 않는다. 즉, 초기화는 하지만 종료 처리는 하지 않으므로 종료처리를 Bean 사용처에서 직접해야 한다. 그 외의 다른 스코프에서는 작동한다.  
 +    * [[http://stackoverflow.com/questions/22848563/predestroy-on-session-scoped-spring-mvc-controllers|참조 @PreDestroy on session scoped ...]] 
 +  * [[https://www.baeldung.com/spring-inject-prototype-bean-into-singleton|Injecting Prototype Beans into a Singleton Instance in Spring]] Prototype scope 객체 얻는 다양한 방법 
 + 
 +==== 구현방법 Provider<T> ==== 
 +<code java> 
 +@Autowired 
 +private Provider<PrototypeBeanClass> prototypeBeanClassProvider; 
 + 
 +... 
 +PrototypeBeanClass bean = prototypeBeanClassProvider.get(); 
 +... 
 +</code> 
 + 
 +==== @Lookup ==== 
 +  * ''@Lookup'' 메소드를 호출하면 매번 새로운 객체를 생성해준다. [[https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/factory/annotation/Lookup.html|@Lookup]] 
 + 
 +<code java> 
 +@Component 
 +public class SingletonLookupBean { 
 +  
 +    @Lookup 
 +    public PrototypeBean getPrototypeBean() { 
 +        return null; 
 +    } 
 +
 +</code>
  
 ===== request/session ===== ===== request/session =====
springframework/scope.txt · 마지막으로 수정됨: 2018/09/17 18:03 저자 kwon37xi