Spring: Spring container Introduction

Spring container in the end is what?

Conceptually: Spring container is the core Spring Framework, is used to manage objects. The container object is created to connect them together, configure them, and manage their entire lifecycle from creation to destruction .

From the concrete images speak: the project which is something the Spring container? In java project, we used to achieve the implementation class org.springframework.context.ApplicationContext interface. In the web project, we use spring.xml - Spring configuration file.

Speaking from the code: a Spring container is an instance of ApplicationContext class implements the interface. In other words, from the code level, Spring container is actually a ApplicationContext (an instance of an object).

 

spring configuration file as follows:

[HTML] View plaincopy
 <? xml Version = "1.0" encoding = "UTF-8"?> 
< Beans 
  xmlns = "HTTP: // www.springframework.org/schema/beans"   
       xmlns: xsi = "HTTP: // www.w3.org/2001/XMLSchema-instance "   
       xsi: schemaLocation =" HTTP: // www.springframework.org/schema/beans   
           HTTP: // www.springframework.org/schema/beans/spring-beans.xsd " 
    <! - here you can add other constraints -> 
    >   

  <bean the above mentioned id = "..." class = "...">   
    <! - here write bean configuration ->   
  </ bean>   
  
  <! - where you can define more of the bean ->   
  
</ Beans>  

We can configure in xml we need a series of bean, Spring will be resolved in accordance with what we are configured after configuration to get the value we need.

Here you can see my article: https://www.cnblogs.com/nhdlb/p/12426941.html , https://www.cnblogs.com/nhdlb/p/12427276.html

 

Spring container type:

Spring provides two different types of containers
Spring BeanFactory container: it is the simplest container, to DI provides basic support
ApplicationContext container: container inherits from ApplicationContext BeanFactory, it includes all the features BeanFactory container, it is generally recommended to use.

ApplicationContext container

Examples of this Spring container commonly used in two ways:

Method a : Looking for path configuration file to instantiate the class container.

ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[]{"spring.xml"});

Method two : looking at the file system configuration file to instantiate the container path.

ApplicationContext ctx = new FileSystemXmlApplicationContext(new String[]{"d:\\beans.xml"});

 

Article reprint to: https://blog.csdn.net/qq_34598667/article/details/83245753

 

Guess you like

Origin www.cnblogs.com/nhdlb/p/12427401.html