spring-spring bean container

1, the basic definition of bean and bean aliases

2, the scope of the bean container

      singleton: Singleton, the entire spring IoC container, Singleton scope bean will generate only one instance.

      prototype: each getBean through the container () method of getting a prototype-scoped bean, will produce a new instance of the bean.

     request: For an HTTP request, request scoped bean will generate only one instance, this means that, in the same HTTP request, each time the program requesting the bean, to give always the same instance. Only use the spring in Web applications, the scope will be truly effective.

      session: For the primary HTTP session, sesion scoped bean will generate only one instance, this means that, in the same HTTP session, each time the program requesting the bean, to give always the same instance. Only use the spring in Web applications, the scope will be truly effective.

      global session: each global HTTP Session per bean. In a typical case, the only effective when using the portlet context. Only use the spring in Web applications, the scope will be truly effective.

      More commonly used is singleton and prototype. For singleton scope bean, bean each request will receive the same instance. Container bean instance is responsible for tracking the state is responsible for maintaining the life cycle of behavior bean instance; prototype scope of bean, bean program each time the id of the request, spring will create a new bean instance, and then returns to the program. In this case, spring bean container only create instances using the new keyword, once created, the vessel is no longer tracking instance, will not maintain state bean instance.

      If you do not specify the scope of the bean, spring container using a singleton scope by default.

      spring configuration files specified by the scope of the bean scope attribute, which can accept singleton, prototype, request, session, globalSession five values.

3, request scope

4, session scope

Guess you like

Origin www.cnblogs.com/ZeroMZ/p/11324701.html