Iv. IOC Container
The IOC , which controls the inversion, realizes the decoupling of the object's life cycle management and the relationship dependency through the container.
ApplicationContext is the most critical entry, and it includes several implementations:
Filesystemxmlapplicationcontext, loads the defined Bean object from the XML file, loads the configuration based on the file system path;
Classpathxmlapplicationcontext, loads the defined Bean object from the XML file, loads the configuration based on the classpath;
Webxmlapplicationcontext, loads the defined Bean object from the XML file, loads the configuration based on the Web application scope;
V. Bean Management 5.1 Scope Singleton
Maintains a single instance (default) in each Spring IoC container.
Prototype
An instance of a bean can be any number.
Request
This scope restricts the bean's definition to an HTTP request. Valid only in the context of Web-aware Spring ApplicationContext.
Session
This scope restricts the bean's definition to an HTTP session. Valid only in the context of Web-aware Spring ApplicationContext.
Global-session
This scope restricts the bean's definition to a global HTTP session. Valid only in the context of Web-aware Spring ApplicationContext.
5.2 Life cycle
The initialization and destruction of the Bean corresponds to the init and destroy two behaviors, which can be observed by implementing the Initializingbean/disposablebean interface to initialize the object and destroy the time.
Code snippet:
Public void throws Exception { System.out.println (this + "--Properties Set");} Public void init () { System.out.println (this + "--init");} Public void destroy () { System.out.println (this + "--destroy");}
In order for spring to gain the opportunity to monitor the destroy behavior, a JVM shutdown callback needs to be registered:
Context.registershutdownhook ();
Init/destroy Intercept
Implement the Beanpostprocessor interface and register to the configuration file
<class= "xxx." Mybeanpostprocessor "/>
5.3 Bean Template
You can typically aggregate a set of properties into a bean template for reuse
<!--Template -<BeanID= "template"Abstract= "true"> < Propertyname= "Support"value= "true" /> < Propertyname= "Count"value= "Ten" /></Bean><BeanID= "Tplbean"class= "Org.springfoo.core.bean.TplBean"Parent= "template"> < Propertyname= "message"value= "I ' m inheritted from template" /></Bean>
POJO definition
Public class Tplbean { private String message; Private Boolean Support ; Private Integer count; ...
Spring Core Technology Overview 2