我正在获取org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException

时间:2015-03-06 04:24:30

标签: 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; 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>

我的档案中有什么错误?我的朋友说我必须在春天为标签添加nameSpace。但是,我不知道那是什么?

1 个答案:

答案 0 :(得分:0)

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

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

但是你实际上没有声明这个命名空间。你需要将它添加到某个地方(在根目录上)。

<beans xmlns="http://www.springframework.org/schema/beans"
       ...
       xmlns:security="http://www.springframework.org/schema/security"
       ...>
    ...
</beans>