Spring (3.2.3), spring3.2.3

Source: Internet
Author: User

Spring (3.2.3), spring3.2.3
BeanFactory & ApplicationContext

Org. springframework. beans. factory. BeanFactory is the most basic Spring container interface, which provides some basic functions for Bean management. The BeanFactory Interface contains the following basic methods:
Object getBean (String name) throws BeansException;
<T> T getBean (String name, Class <T> requiredType) throws BeansException;
Boolean containsBean (String name );
Class <?> GetType (String name) throws NoSuchBeanDefinitionException;

Org. springframework. context. applicationContext is org. springframework. beans. factory. beanFactory sub-interfaces not only provide features supported by BeanFactory, ApplicationContext also provides some additional features, such as international support, event mechanism, and resource access.

 

Basic Structure of Spring configuration file
<?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-3.0.xsd">        <bean id="..." class="..." >        <property name="..." value="..." />        <property name="..." ref="..." />    </bean>    </beans>

 

Instantiate a container

Load the configuration file by File System Path:

ApplicationContext appCtx = new FileSystemXmlApplicationContext("src/applicationContext.xml");

Load multiple configurations by class path:

ApplicationContext appCtx = new ClassPathXmlApplicationContext("applicationContext.xml");

Load multiple configuration files:

ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"services.xml", "daos.xml"});

 

Use Spring container
ExampleBean example = appCtx.getBean("example", ExampleBean.class);

 

Related Article

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.