Getting Started with spring

Source: Internet
Author: User
Tags xmlns

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

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.