2014-03-30 58 views
2

我的bean配置文件如下定影HTTP标签

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


</beans:beans> 

我不能够添加以下到它,虽然我已经进口安全3.1.1罐子

<http> 
    <intercept-url pattern='/home*' access='ROLE_USER,ROLE_ADMIN' /> 
</http> 

回答

1

您可能会想要使用security命名空间。另一种方法是使security为默认名称空间 - 您必须决定是否要这样做。

<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:beans="http://www.springframework.org/schema/beans" 
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:security="http://www.springframework.org/schema/security" 
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"> 

    <security:http> 
     <security:intercept-url pattern='/home*' access='ROLE_USER,ROLE_ADMIN'/> 
    </security:http>  
</beans:beans> 

不仅有我加security:到你所使用的标签的前面,但我已经添加的xmlns:顶部的安全,其架构位置沿。

+0

谢谢。但一个警告刚刚出现。无法找到元素安全性的Spring命名空间处理程序:http –

+0

请解释:您在使用什么IDE?你正在编写一个servlet或你自己的可运行jar吗?请显示您用来运行所有内容的代码。 – Rajit

+0

问题已经通过在每个子标签的开始处添加'security:'来解决:'security:logout' –