Spring container manages various files and spring container

Source: Internet
Author: User

Spring container manages various files and spring container

1. Import files

<Import resource = "applicationContext-dataSource.xml"/>

2. Reference The resource configuration file

<Context: property-placeholder location = "classpath: jdbc. properties, classpath: xxx. properties "/> or <context: property-placeholder location =" xxx. properties "ignore-unresolvable =" true "/> <context: property-placeholder location =" xxx. properties "ignore-unresolvable =" true "/>

If no ignore-unresolvable = "true" is referenced for multiple times, an exception "cocould not resolve placeholder" will occur.

In Spring 2.5, <context: property-placeholder> does not have the ignore-unresolvable attribute, so the above method cannot be used for configuration,

You can change the format as follows:

<bean id="propertyConfigurer"    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath:/jdbc.properties</value></list></property></bean>

Use the Referenced File Content:

<bean name="userInfo" class="test.UserInfo">    <property name="username" value="${db.username}"/>    <property name="password" value="${db.password}"/>  </bean> 

3. Reference The resource file in the project java code

For example, reference the content in xxx. properties

First, configure the following in the spring container:

<util:properties id="settings" location="/WEB-INF/xxx.properties"></util:properties>

Java code usage:

@ Value ("# {settings}") private Properties file; or @ Value ("# {settings ['test. abc']}") private String url;

 


All the beans in the Spring configuration file are instantiated when the container is loaded.

If I remember correctly, spring Singleton mode containers are instantiated when loaded, such as configuring struts filter, of course, when configuring the bean of action, the Default policy of spring is to generate the bean when no request is made, and it is not instantiated when the container is loaded. For details, refer to the spring book. It should be very detailed. The related only points should be the bean lifecycle.

When can entity classes in spring be handed over to spring container management?

When the container starts, load the configuration file through web. xml to generate a globally unique beanfactory, generate single-State instances, and weave dependencies.

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.