开发者

"JSR-303 Provider is on the classpath" Means

开发者 https://www.devze.com 2023-04-07 10:36 出处:网络
I am using Spring MVC 3. Here is the my model, public class MarketPlace { @NotNull(message=\"This Template Name is required\")

I am using Spring MVC 3. Here is the my model,

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;
    }

}

and here is the controller method,

public String PublishForm(@Valid MarketPlace m, BindingResult result) {
    if (result.hasErrors()) {
        return "Error";
    }
    return "Sucess";
}

But hasErrors is always false. Then I put these lines in d开发者_高级运维ispather-servelet,

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

mvc:annotation-driven /

But now now, NetBean showing me this error,

The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven.

Some people suggests me to "Set JSR-303 Provider is on the classpath"

What does this means. I have these jars in my application,

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 

Edit:

<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="demo.htm">DemoAppMarketController ................................. <bean name="indexController" class="Controller.IndexControler"


You have to be sure that the following xsi:schemaLocation entries exist:

http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  

In addition look at this tutorial it explains how to work JSR-303 Providers.

http://www.openscope.net/2010/02/08/spring-mvc-3-0-and-jsr-303-aka-javax-validation/

Update: Frankly, I prefer another way for URL mapping: all jsp requested are mapped to *.html URLS.

Now your Dispatcher servlet looks like that:

 <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>

Than your Spring URL mapping looks like that:

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>
0

精彩评论

暂无评论...
验证码 换一张
取 消