<bean id="xxx" class="xxx.yyy.zzz" scope="singleton" >
<property name="message" value="Spring Bean"/>
</bean>
Singleton
하나의 Bean에 대해서 Spring IoC Container 내에 하나의 객체만 존재
Prototype
하나의 Bean에 대해서 Spring IoC Container 내에 다수의 객체 존재 가능
Request
하나의 Bean에 대해서, 하나의 HTTP Request 라이프사이클 안에서는 하나의 객체만 존재 (= 각 HTTP Request는 고유한 Bean을 하나씩 가짐)
Session
하나의 Bean에 대해서, 하나의 HTTP Session 라이프사이클 안에서는 하나의 객체만 존재 (= 각 HTTP Session은 고유한 Bean을 하나씩 가짐)
Global Session
하나의 Bean에 대해서, 하나의 Global HTTP Session 라이프사이클 안에서는 하나의 객체만 존재 (= 각 Global HTTP Session은 고유한 Bean을 하나씩 가짐)
(+ 일반적으로 Portlet Context 안에서 유효)
Request, Session, Global Session은 MVC Web Application 에서만 유효
Bean으로 등록하는 Class에 Annotation으로 Scope를 설정해줄 수 있다.
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
@Component
@Service("userBean")
@Scope("prototype")
public class UserController {
}