程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长


+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

Spring 验证在来自 ServletContext 资源的 XML 文档中有错误

发布于2022-01-08 22:21     阅读(1121)     评论(0)     点赞(15)     收藏(4)


我在我的注册页面中应用了 spring 验证。但是我的应用引擎服务器的服务器日志中显示了以下错误。

 javax.servlet.UnavailableException: 
    org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
    Line 22 in XML  document from ServletContext resource 
    [/WEB-INF/spring/appServlet/servlet-context.xml] is invalid; 
    nested exception is org.xml.sax.SAXParseException;
    lineNumber: 22; columnNumber: 30; 
    cvc-complex-type.2.4.c: The matching wildcard is strict, 
    but no declaration can be found for element 'property'.

我的代码如下:

<?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-3.0.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd 
        http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd >


    <beans:bean name="/register" class="com.my.registration.NewUserRegistration">
        <property name="validator">
            <bean class="com.my.validation.UserValidator" />
        </property>
        <beans:property name="formView" value="newuser"></beans:property>
        <beans:property name="successView" value="home"></beans:property>
    </beans:bean>
    <beans:bean
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <beans:property name="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

</beans:beans>

解决方案


您文档的默认 XML 命名空间是http://www.springframework.org/schema/mvc,因此您应该为来自其他命名空间的所有元素使用命名空间前缀,包括来自http://www.springframework.org/schema/beans命名空间的元素

<beans:property name="validator">
    <beans:bean class="com.my.validation.UserValidator" />
</beans:property>

或者,您可以配置http://www.springframework.org/schema/beans为默认命名空间:

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

显然,在这种情况下,您需要为命名空间中的元素使用命名空间前缀mvc(如果有的话)。

也可以看看:



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接:http://www.javaheidong.com/blog/article/375976/7edb7e2c34c839a1b853/

来源:java黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

15 0
收藏该文
已收藏

评论内容:(最多支持255个字符)