Spring configuration file header information

 

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:task="http://www.springframework.org/schema/task"
	xsi:schemaLocation="http://www.springframework.org/schema/beans  
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context.xsd
		   http://www.springframework.org/schema/task
		   http://www.springframework.org/schema/task/spring-task.xsd">

 

I have been using spring for several years, but every time I have to configure the spring project myself, I have a headache. I copy other people's configuration files through the network, and then I accidentally report an error, so I want to find out today.

The above is a spring-context configuration file xmlns section:

xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

This is a necessary part of each configuration file, which is the root of spring.

Declare the default namespace for xml files, indicating the default namespace for all tags that do not use other namespaces.

Declare an XML Schema instance, and then use the schemaLocation attribute.

 

 

xmlns:context="http://www.springframework.org/schema/context"

 This is the tag in the spring configuration file that needs to use the context (for component tags), declare the namespace prefixed with context, and the URL that follows is used to indicate that the address of the namespace will not be used by the parser to find information. Its only function is to give the namespace a unique name. When a namespace is defined in an element's start tag, all child elements with the same prefix are associated with the same namespace. Then others such as MVC (for mvc tags) and tx (for transaction tags) have the same meaning.

 

The xsi:schemaLaction section:

http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

It is to specify the xsd specification file for the namespace configured above, so that when you perform the following specific configuration, you will give corresponding prompts according to these xsd specification files, such as how each tag is written, and what attributes are there? It can be intelligently prompted to prevent errors in the configuration and it is not easy to troubleshoot. When starting the service, the configuration will also be verified according to the xsd specification. But here you need to configure the xsd specification file for the mvc, aop, tx, etc. configured in your xmlns above.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326126787&siteId=291194637