spring in action 2.0读书笔记(2)
spring in action 2.0读书笔记(二)
Bean scope
singleton:Scopes the bean definition to a single instance per Spring container (default).
prototype:Allows a bean to be instantiated any number of times (once per use).
request:Scopes a bean definition to an HTTP request. Only valid when used with a webcapable Spring context (such as with Spring MVC).
session:Scopes a bean definition to an HTTP session. Only valid when used with a webcapable Spring context (such as with Spring MVC).
global-session:Scopes a bean definition to a global HTTP session. Only valid when used in a portlet context.
Creating beans from factory methods.
The init-method attribute specifies a method that is to be called on the bean immediately upon instantiation. Similarly, destroy-method specifies a method that is called just before a bean is removed from the container.
Bean scope
singleton:Scopes the bean definition to a single instance per Spring container (default).
prototype:Allows a bean to be instantiated any number of times (once per use).
request:Scopes a bean definition to an HTTP request. Only valid when used with a webcapable Spring context (such as with Spring MVC).
session:Scopes a bean definition to an HTTP session. Only valid when used with a webcapable Spring context (such as with Spring MVC).
global-session:Scopes a bean definition to a global HTTP session. Only valid when used in a portlet context.
<bean id="theStage" class="com.springinaction.springidol.Stage" factory-method="getInstance" /> <bean id="kenny" class="com.springinaction.springidol.Instrumentalist" init-method="tuneInstrument" destroy-method="cleanInstrument"> <property name="song" value="Jingle Bells" /> <property name="instrument" ref="saxophone" /> </bean>
Creating beans from factory methods.
The init-method attribute specifies a method that is to be called on the bean immediately upon instantiation. Similarly, destroy-method specifies a method that is called just before a bean is removed from the container.