我正在使用 Spring MVC 3。这是我的模型,
public class MarketPlace {
@NotNull(message="This Template Name is required")
@Size(max=50)
private String templateName;
public String getTemplateName() {
return templateName;
}
public void setTemplateName(String templateName) {
this.templateName = templateName;
}
}
这是 Controller 方法,
public String PublishForm(@Valid MarketPlace m, BindingResult result) {
if (result.hasErrors()) {
return "Error";
}
return "Sucess";
}
但是 hasErrors 始终为 false。 然后我将这些行放入 dispather-servlet 中,
xmlns:mvc="http://www.springframework.org/schema/mvc"
................
mvc:annotation-driven /
但是现在,NetBean 向我显示此错误,
The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven.
有些人建议我 “设置 JSR-303 提供程序位于类路径上”
这是什么意思。 我的应用程序中有这些 jar ,
lib\slf4j-api-1.6.2.jar,
build/web/Resources/validation-api-1.0.0.GA.jar,
build/web/Resources/hibernate-validator-4.2.0.Final.jar
编辑:
最佳答案
您必须确保以下 xsi:schemaLocation
条目存在:
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
此外,请查看本教程,它解释了如何使用 JSR-303 提供程序。
http://www.openscope.net/2010/02/08/spring-mvc-3-0-and-jsr-303-aka-javax-validation/
更新: 坦率地说,我更喜欢另一种 URL 映射方式: 所有请求的 jsp 都映射到 *.html URL。
现在您的 Dispatcher servlet 看起来像这样:
<display-name>MyServlet</display-name>
<servlet>
<servlet-name>MyServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
你的 Spring URL 映射看起来像这样:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
关于java - "JSR-303 Provider is on the classpath"含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7538383/