사용자 도구

사이트 도구


springframework:scope

차이

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

차이 보기로 링크

다음 판
이전 판
springframework:scope [2012/07/31 16:00]
kwon37xi 새로 만듦
springframework:scope [2018/09/17 18:03]
kwon37xi
줄 1: 줄 1:
 ====== Spring Bean Scope ====== ====== Spring Bean Scope ======
-===== prototype =====+  * [[https://www.baeldung.com/spring-lookup|@Lookup Annotation in Spring]] 
 + 
 +===== prototype Scope =====
   * 매번 객체 새로 생성할 필요가 있을 경우 사용한다.   * 매번 객체 새로 생성할 필요가 있을 경우 사용한다.
 +  * [[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 Scope =====
 +  * 웹 Request/Session 이 생성될 때마다 객체를 새로 생성하여 넘겨준다.
 +  * [[http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/beans.html#beans-factory-scopes-other|Bean Factory Scopes Other]]
 +  * [[http://tedyoung.me/2011/04/21/spring-request-scope/|Spring Request Scope 객체 생성하기]]
 +  * [[http://stackoverflow.com/questions/3320674/spring-how-do-i-inject-an-httpservletrequest-into-a-request-scoped-bean|HttpServeletRequest]] 객체를 request 스코프 빈에 주입하려면 ''@Autowired private HttpServletRequest request;'' 형태를 사용하면 된다.
 +  * [[http://stackoverflow.com/questions/8887831/how-do-i-constructor-autowire-httpservletresponse-in-spring-3-1|HttpServletResponse 주입 방법]]
 +    * ''ServletWebRequest'' 를 주입 받은 뒤에 ''getResponse()''를 한다. 실질적으로 Http Request/Response 관련 대부분의 정보를 확보할 수 있다.
springframework/scope.txt · 마지막으로 수정됨: 2018/09/17 18:03 저자 kwon37xi