Spring learning notes: First Reading Spring and spring learning notes

Source: Internet
Author: User

Spring learning notes: First Reading Spring and spring learning notes

1. Brief Introduction

At the bottom layer of spring ioc, the xml file is configured first, then the factory is created, the configuration file is parsed using dom4j, and finally completed through reflection. The steps are similar. The specific code spring helps you. Now we only need to configure xml, load the configuration file, and then create an object.

2. Implementation

First, create a project and import the jar package, which is roughly as follows:

After the jar package is imported, write a User class, which contains the add method:

Next, we will write a configuration file named applicationContext. xml, which is officially defined as the file name. Of course, bean1.xml is also available here:

The constraints in the front part of this configuration file can be found in the jar package html, almost this path: spring-framework-3.2.8.RELEASE \ docs \ spring-framework-reference \ html, to the bottom of the called xsd-config.html, open and turn to the bottom of the page:

Copy the constraint.

To prompt when writing xml, We need to configure the XML Catalog. Copy this section first:

Go to windows preferences and find the tab panel:

Of course, I will add it here. Click add if it is not added:

Paste the copied file to the Key. The location address is the xsd corresponding to the jar package:

Among the most popular versions, I only have 3.2 and should have 4x. After selection, the drop-down will become like this:

Select Schema location. OK.

In this xml, we configure a bean:

Id is called user, class is the path, corresponding to the User class written above

After the configuration is complete, we create a new test class:

As mentioned in the annotation step, the user in getBean is the id in xml.

Run the following command:

You can see that the operation is successful. No problem.

If I change the value of getBean here, for example, I change the value of userd.

Here it does not correspond to iid = "user" in xml, and an error is returned, as shown below:

The prompt "No bean named userd" is displayed.

3. Conclusion

This small program is relatively simple, and I hope to help my friends who are just learning spring.

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.