2014-03-30 54 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' –