在 spring 配置文件错误中出现错误:与元素类型“beans”关联的属性“xmlns”的值不能包含“<”字符

Posted

技术标签:

【中文标题】在 spring 配置文件错误中出现错误:与元素类型“beans”关联的属性“xmlns”的值不能包含“<”字符【英文标题】:Getting error in spring config file error : The value of attribute "xmlns" associated with an element type "beans" must not contain the '<' character 【发布时间】:2018-09-17 22:13:33 【问题描述】:

http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.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">

<!-- Scans the classpath of this application for @Components to deploy as
    beans -->
<context:component-scan base-package="com.test" />

<!-- Configures the @Controller programming model -->
<mvc:annotation-driven />

<!-- Specifying the Resource location to load JS, CSS, Images etc -->
<mvc:resources mapping="/resources/**" location="/resources/" />

<!-- View Resolver -->
<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/WEB-INF/pages/" />
    <property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
    <property name="basename" value="classpath:messages" />
</bean>
</beans>

【问题讨论】:

【参考方案1】:

看起来您缺少 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:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.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">

<!-- Scans the classpath of this application for @Components to deploy as
    beans -->
<context:component-scan base-package="com.test" />

<!-- Configures the @Controller programming model -->
<mvc:annotation-driven />

<!-- Specifying the Resource location to load JS, CSS, Images etc -->
<mvc:resources mapping="/resources/**" location="/resources/" />

<!-- View Resolver -->
<bean id="viewResolver"
    class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  <property name="prefix" value="/WEB-INF/pages/" />
  <property name="suffix" value=".jsp" />
</bean>
<bean id="messageSource"
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
  <property name="basename" value="classpath:messages" />
</bean>
</beans>

【讨论】:

以上是关于在 spring 配置文件错误中出现错误:与元素类型“beans”关联的属性“xmlns”的值不能包含“<”字符的主要内容,如果未能解决你的问题,请参考以下文章

spring与struts2整合出现错误HTTP Status 500 - Unable to instantiate Action

SpringMVC利用Spring自带验证框架验证获取错误信息出现乱码问题

Spring 问题:出现意外错误(类型=未找到,状态=404)

今天遇到了一个Spring出现的一个未知错误,分享下

Spring Faces 错误面孔:flow-builder-services

Spring集成测试