Spring Core Technology Overview 2

Source: Internet
Author: User

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:

    1. Filesystemxmlapplicationcontext, loads the defined Bean object from the XML file, loads the configuration based on the file system path;

    2. Classpathxmlapplicationcontext, loads the defined Bean object from the XML file, loads the configuration based on the classpath;

    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.