gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 09:33:22 24 4
gpt4 key购买 nike

我在我的注册页面中应用了 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 命名空间的元素使用命名空间前缀(如果有的话)。

另请参阅:

关于java - Spring 验证在来自 ServletContext 资源的 XML 文档中有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12245124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com