2016-05-28 2 views
-1

Моего конфигурационного файла ярового выглядят следующим образомSpring проблема безопасности с Http тег

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

<http auto-config="true"> 
     <security:intercept-url pattern="/admin**" access="ROLE_USER" /> 
    </http> 

    <authentication-manager> 
     <authentication-provider> 
     <user-service> 
     <user name="test" password="test" authorities="ROLE_USER" /> 
     </user-service> 
     </authentication-provider> 
    </authentication-manager> 

</beans> 

Однако я столкнулся следующее сообщение об ошибке

cvc-complex-type.2.4.a: Invalid content was found starting with element 'http'. One of '{"http://www.springframework.org/schema/beans":import, "http://www.springframework.org/schema/beans":alias, "http:// 
www.springframework.org/schema/beans":bean, WC[##other:"http://www.springframework.org/schema/beans"], "http://www.springframework.org/schema/beans":beans}' is expected. 

Что может быть не так? Перекрестная ошибка ошибки, показанная Eclipse, правильная, где начинается тег http.

UPDATE Я использую Gradle и мой файл build.gradle имеет следующий зависимости для весны:

compile 'org.slf4j:slf4j-api:1.7.12' 
    compile 'com.googlecode.json-simple:json-simple:1.1.1' 
    compile 'de.grundid.opendatalab:geojson-jackson:1.0' 
    compile 'org.springframework:spring-web:4.2.5.RELEASE' 
    compile 'org.springframework:spring-webmvc:4.2.5.RELEASE' 
    compile 'org.springframework:spring-jdbc:4.2.5.RELEASE' 
    compile 'org.springframework:spring-core:4.2.5.RELEASE' 
    compile 'org.springframework:spring-context:4.2.5.RELEASE' 
    compile 'org.springframework:spring-aop:4.2.5.RELEASE' 
    compile 'org.springframework.security:spring-security-web:4+' 
    compile 'org.springframework.security:spring-security-config:4+' 

следующих зависимости Spring в пути сборки моего проекта: enter image description here

+0

Не могли бы вы поделиться своим pom. Xml подробности для весенней безопасности –

+0

Эй @MdFaraz, пожалуйста, проверьте обновленную часть :). – Smrita

ответ

2

Вашего XML документ имеет пространство имен Spring beans как пространство имен по умолчанию. Элемент http и другие элементы Spring Security находятся в пространстве имен безопасности. Вы должны указать префикс:

<security:http auto-config="true"> 
    <security:intercept-url pattern="/admin**" access="ROLE_USER" /> 
</security:http> 

<security:authentication-manager> 
    <security:authentication-provider> 
    <security:user-service> 
     <security:user name="test" password="test" authorities="ROLE_USER" /> 
    </security:user-service> 
    </security:authentication-provider> 
</security:authentication-manager> 
+0

Привет после добавления пространства имен безопасности Я столкнулся с другой ошибкой: Несколько аннотаций, найденных в этой строке: \t - cvc-complex-type.2.4.c: Соответствующий шаблон является строгим, но для безопасности элемента не найдено объявления: HTTP. \t - schema_reference.4: Не удалось прочитать документ схемы «http://www.springframework.org/schema/security/spring-security.xsd», \t, поскольку 1) не удалось найти документ; 2) документ не может быть прочитан; 3) корневой элемент документа не . – Smrita

+0

@Smrita, что XSD возвращает 404 из браузера, вот в чем проблема. Конфигурация пространства имен из моего [весового файла безопасности] (https://github.com/gmazza/tightblog/blob/trunk/app/src/main/webapp/WEB-INF/security.xml) может помочь, безопасность XSD использует (http://www.springframework.org/schema/security/spring-security-4.0.xsd) всплывающее сообщение. –

+0

404 - это нормально, xsd следует найти в пути к классам, но если для вас работает xsd, зависящий от версии, пойдите с этим. – holmis83

Смежные вопросы