The Spring Learning Path

Source: Internet
Author: User

1. What is Spring?

When I first approached Java, I wondered why everyone was talking about spring, as if Java was spring, and what was spring? In fact, he is a container frame, you can think of it as a toolbox, it can help you quickly Java development.

2, how to use spring?

Spring is especially easy to use, download the jar package, import the project, write the corresponding configuration file, you can use it. Specific tutorial, Baidu a search a lot of, I will not repeat the writing. Here I'll talk about three ways to load the Spring app context:

①classpathxmlapplicationcontext: By loading the XML file under the Classpath, This is the most common , that is, loading the applicationcontext.xml file under the SRC directory;

ApplicationContext context=new classpathxmlapplicationcontext ("Applicationcontext.xml");

②filesystemxmlapplicationcontext: Load the configuration file with the specified absolute path;

ApplicationContext context=new filesystemxmlapplicationcontext ("D:***/***/***/applicationcontext.xml");

③xmlwebapplicationcontext: Read the configuration file load under Web application.

ApplicationContext context=new xmlwebapplicationcontext ("Applicationcontext.xml");

If this is a Web project, then you need to configure the following XML:

<!--load Spring container configuration--
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

If only the above configuration, the/web-inf/applicationcontext.xml configuration file is loaded by default to initialize the ApplicationContext instance, If you want to specify a configuration file, then add the following configuration information to Web. xml

<!--set the spring container to load all the configuration file paths--
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:config/applicationContext.xml</param-value>
</context-param>

Then write the code inside the project to get:

ApplicationContext context = Webappliacationcontextutils.getwebapplicationcontext (Getservletcontext ());

The Spring Learning Path

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.