What is the difference in xmlns definition in spring configuration file

Spring Training I found two types of xmlns definition in the Spring configuration file. Starting from this:

<beans xmlns="http://www.springframework.org/schema/beans" 

which I found in the spring documentation

And the second begins with this:

  <beans:beans xmlns="http://www.springframework.org/schema/mvc" 

Both work fine. One of the differences that I noticed is that you should start all the tags with the name beans if you are using the second definition, for example:

 <beans:import resource="hibernate-context.xml" /> 

which could otherwise be written as

  <import resource="hibernate-context.xml" /> 

What is the main difference they make?

+4
source share
1 answer

This does not apply to Spring, but refers more to XML and namespaces - here's the link: http://www.w3schools.com/xml/xml_namespaces.asp , http://en.wikipedia.org/wiki/XML_namespace

Just to summarize: In the first case

 <beans xmlns="http://www.springframework.org/schema/beans" 

makes the beans schema the default for this xml file, which allows you to refer to elements in this beans schema without a namespace prefix. So, where is this schema defined - a reference to the schema is usually included in the schemaLocations attribute like this:

 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd" 

What is said above is that the definition of http://www.springframework.org/schema/beans is present in the corresponding .xsd file

In your second instance -

 <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:beans="http://www.springframework.org/schema/beans" 

Now you define the mvc namespace as the default namespace, so in this case, any elements in the mvc scheme can be referenced without a prefix, but if you want to refer to any elements of the beans scheme, you will have to refer to it using the beans: prefix, as for beans:import in your example

+5
source

All Articles