Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 我得到org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException_Java_Xml_Spring_Applicationcontext - Fatal编程技术网

Java 我得到org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException

Java 我得到org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException,java,xml,spring,applicationcontext,Java,Xml,Spring,Applicationcontext,我的代码中出现以下异常 org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 38 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 38; c

我的代码中出现以下异常

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 38 in XML document from ServletContext resource [/WEB-INF/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 38; columnNumber: 40; The prefix "security" for element "security:http" is not bound.
我的applicationContext.xml文件是

<?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: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:tx="http://www.springframework.org/schema/tx"
   xsi:schemaLocation="
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
    http://www.springframework.org/schema/data/jpa
    http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

<context:annotation-config />
<context:component-scan base-package="com.mycompany.myproject">
    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>

<mvc:annotation-driven/>

<!-- wro setup -->
<bean id="wroProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
    <property name="location" value="/WEB-INF/wro.properties" />
</bean>
<bean id="wroFilter" class="ro.isdc.wro.http.ConfigurableWroFilter">
    <property name="properties" ref="wroProperties"/>
</bean>

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

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


我的文件中有什么错误?我的朋友说我必须在spring中为标记添加名称空间。但是,我不知道那是什么?

您的上下文文件正在尝试访问元素中的
安全性
命名空间:

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

但实际上没有任何地方声明该名称空间。您需要将其添加到某个位置(根上)


...

了解术语,了解文件格式。。。您使用的是XML,这是基本知识…现在,我添加了名称空间,但这次我得到了以下例外org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自ServletContext资源[/WEB-INF/applicationContext.xml]的xml文档中的第39行无效;嵌套异常为org.xml.sax.saxpasseeption;行号:39 ;;栏目号:40;cvc复杂类型.2.4.c:匹配的通配符是严格的,但找不到元素“security:http”的声明
<beans xmlns="http://www.springframework.org/schema/beans"
       ...
       xmlns:security="http://www.springframework.org/schema/security"
       ...>
    ...
</beans>