1. Introduction of Spring Jar file
Libs/spring-beans-3.2.2.release.jar
Libs/spring-context-3.2.2.release.jar
Libs/spring-context-support-3.2.2.release.jar
Libs/spring-core-3.2.2.release.jar
Libs/spring-expression-3.2.2.release.jar
Need:
Commons-logging-1.1.1.jar
2. Need to add spring configuration file
The name of the configuration file can be named casually, but it is best to have practical meaning.
For example:
Spring-dao.xml
Spring-service.xml
Spring.xml
3, spring configuration file How to introduce beans constraints
---spring-framework-3.2.2.release-dist/spring-framework-3.2.2.release/docs/spring-framework-reference/html/ Index.html
In the directory:
5.2.1. Configuration Metadata Click to enter
The original information can be copied:
<?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 ">
</beans>
4, the following is instantiated: container
//Read the classes path under the file parameter dynamic parameter, a single parameter, an array, you can use wildcard characters, etc.
ApplicationContext context = new Classpathxmlapplicationcontext ( "Spring.xml");
5, get bean in container
Hellodao Hellodao = (Hellodao) context.getbean ("Hellodaoimpl");
HelloService HelloService = Context.getbean ("Helloserviceimpl", Helloservice.class);
6, the spring configuration file can be imported into a file with the import tag
<import resource= "Spring-dao.xml"/>
<import Resource= "Spring-service.xml"/>
7, Spring container management bean
Bean Properties
ID: Identity Unique
Class: Class
Scope: Scope Singleton prototype request session
Lazy-init:default=false, False, true
Lazy-init combine scope= Singleton use
scope= "singleton" lazy-init= "Default"--Description: The container has been loaded to instantiate the object
scope= "singleton" lazy-init= "true"- Description: The container has been loaded when used to the object, instantiate the object