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.