Learner
Learner

Reputation: 21393

Understanding Spring beans tag declaration

I am new to Spring and trying to understand the beans tag that is declared in my spring configuration file like this:

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

I am trying to understand these 5 lines of my code. The first line says that it is an XML file. Cans someone please help me in understanding the other 4 lines, and the reason to provide that information to Spring application.

Upvotes: 0

Views: 543

Answers (2)

Vineet
Vineet

Reputation: 897

It hasn't got anything to do with Spring. It's XML & Schema basics.

Basically all the tags that you'll use in the xml document have to be predefined somewhere. Similar to declaring your variables before using them. xmlns defines the namespace (akin to packages) where these are stored. Then schemaLocation actually tells the file to refer for that namespace. For the full details regarding syntax, it's best to through the tutorials.

You also might want to go through this as to why the http://www.w3.org/2001/XMLSchema-instance namespace doesn't have a schema file defined.

Upvotes: 2

Florian Schaetz
Florian Schaetz

Reputation: 10652

The other lines only define some prefixes / namespaces that you then can use in your XML file. See here.

Upvotes: 0

Related Questions