2016-09-21 180 views
0

是什么Spring XML配置:豆类:豆类VS豆

<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="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-4.2.xsd 
    http://www.springframework.org/schema/security 
    http://www.springframework.org/schema/security/spring-security-4.1.xsd"> 

<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:security="http://www.springframework.org/schema/security" 
     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 
        http://www.springframework.org/schema/security 
        http://www.springframework.org/schema/security/spring-security.xsd"> 

在前者的区别,安全配置为

<http auto-config="true"> 

     <intercept-url pattern="/login" access="permitAll()" /> 
</http> 

而在后者将被配置为

<security:http auto-config="true"> 

     <security:intercept-url pattern="/login" access="permitAll()" /> 
</security:http> 

我不确定这两种模式格式之间的功能差异。也有人可以建议哪些是可喜的或哪些情况下哪些更可取?

+2

请参见[XML名称空间](http://www.w3schools.com/xml/xml_namespaces.asp)。在你的第一个片段中,* security *命名空间很可能被用作基本命名空间。在后面的* beans *名称空间被用作基名称空间 –

+0

谢谢,这是一个有用的指针。 – Jake

回答

2

标签beans:beansbeans标签从beans命名空间和标签beans指从默认命名空间beans标签。

如果默认名称空间是beans - 根本没有差别。

3

至少有两点不同

  • 第一就是语法:豆类是默认的命名空间或不

  • 第二可能会导致一些(佩塔尔·伊万诺夫在他answer解释这一点) (当您更新弹簧或弹簧安全性时):

带版本号v的XSD :S没有版本号

XSD在您第一次剪掉你使用http://www.springframework.org/schema/beans/spring-beans-4.2.xsdhttp://www.springframework.org/schema/security/spring-security-4.1.xsd - 在这里你所使用的XSD的(这是确定的是春春的安全性有不同的数字)

一个修复版本在第二个剪辑中,您使用了http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/security/spring-security.xsd。在这种情况下,Spring将使用您使用的弹簧和弹簧安全罐支持的最新架构。