spring security命名空间配置


applicationContext-security.xml命名空间配置,官方提供了两种配置方案

  • 第一种、命名空间用beans开头,但是在配置中一直需要用来配置。
1
2
3
4
5
6
7
8
9
<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-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">

...
</beans>
  • 第二种、命名空间用security开头,在配置中不需要security前缀,但是bean的配置需要用配置。
1
2
3
4
5
6
7
8
9
<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-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security.xsd">

...
</beans:beans>

第一行的xmlns=”http://www.springframework.org/schema/security"决定此配置文件默认schema为security,故涉及security命名空间元素都可省略前缀security。同理,当xmlns="http://www.springframework.org/schema/beans"时,则配置文件默认schema为beans,故可省略beans前缀,直接使用定义beans命名空间元素。

PS:schemaLocation里的URI可在对应的类库包的META-INF的*.schemas文件中查看。

官方链接