Spring: configuration parsing of configuration file header

Recently, spring MVC is used in the company's projects, so I have to learn from it. I believe you should see a lot of spring configuration files, so what do you know about the head of configuration files? Let me share some of my opinions with you:

First, take a familiar header configuration file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    <!-- Definition controller Scanning package -->
    <context:component-scan base-package="com.example.controller" />
    <mvc:annotation-driven />
    <!-- Processing static resources -->
    <!-- Configure view resolver -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
       <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
       <property name="prefix" value="/WEB-INF/jsp/"/>
       <property name="suffix" value=".jsp"/>


1.xmlns=http://www.springframework.org/schema/beans and xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance are all necessary spring configuration files

2.xmlns:xxx is the namespace of xml. If you don't expand the namespace, you can simply understand which modules of spring you want to use. The first point is that xmlns="http://www.springframework.org/schema/beans It is necessary, because beans is the root of spring. If you don't even have this, you won't be able to use the configuration file of spring. There are three namespaces in this configuration file, namely xmlns:p, xmlns:mvc, xmlns:context. With these namespaces, you can use < context: component / > < MVC: annotation driven / > If you don't have these namespaces, you can use the < context: component / > < MVC: annotation driven / > functions to report errors!

3. Here is xsi:schemaLocation. What is this used for? In fact, the xsd specification file is specified for the above configured namespace, so you will give corresponding prompts according to these xsd specification files when you carry out the following specific configuration, such as how to write each tag, and what attributes can be intelligently prompted to prevent errors in configuration and not easy to troubleshoot. When starting the service, you will also follow the xsd specification Configuration for verification.

4. The uri of the. XSD file in the configuration file is http://www.springframework.org/schema /.... XSD. So the problem is, do you really want to find the. XSD file on the Internet? Of course not.

Open spring-webmvc-4.2.3. Release. Jar > > meta-inf > > spring. Schemas and you will see the following:


When you see these http://www.springframework.org/schema/.......Xsd contents, you should understand that, in fact, http: //www.springframework.org/schema/mvc/spring-mvc.xsd really points to the location
org/springframework/web/servlet/config/spring-mvc-4.2.xsd, then open the uri to see what's there

As expected, the xsd file is here And so do the others

The language organization is a bit messy. I'm sorry. After careful observation, it's quite regular. You can also save a spring file you have configured, and then copy it directly when you use it later!

This is where I wrote. I hope I can help my friend who just learned spring!!

197 original articles published, 491 praised, 160000 visitors+
Private letter follow

Tags: Spring xml JSP encoding

Posted on Mon, 16 Mar 2020 21:23:26 -0700 by cshinteractive