problems with validation files Spring mvc 3
I'm having some problem with the Validation files in my Spring 3 project. I have a very basic validation project for tests thats the bean:
public class User {
@NotEmpty(message="no blank name")
@Size(min=2, max=20)
private String name="";
@NotEmpty(message="no blank email")
@Email
private String email="";
......getters and setters...... The function within the controller that accepts the request from the Form page and makes the necessary validation is:
@RequestMapping(value="/displayUser",method=RequestMethod.POST)
public String displayUser(@Valid User user, Model model,BindingResult result){
if(result.hasErrors()){
return "form";
}
userList.add(user);
model.addAttribute("user",user);
return "redirect:displayUser";
}
But i dont think the code is the cause of the problem, as as soon as i start the server and run the project "which has always been working, since i test other spring things in there" i get the following Exceptions:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.Loc开发者_运维问答alValidatorFactoryBean#0': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1401)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450)
org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290)
org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:287)
org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:189)
org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:557)
org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:842)
org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:416)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:443)
org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:459)
org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:340)
org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:307)
org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:127)
javax.servlet.GenericServlet.init(GenericServlet.java:212)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:613)
Do you have any idea where thre problem could be? I'm trying to figure out but nothing, P.S.: I use Tomcat 6 and i have just downloaded the:
hibernate-validator-4.0.2.FINAL.jar
and
validation-api-1.0.0.GA.jar
It looks to me like the class org.springframework.validation.beanvalidation.LocalValidatorFactoryBean
cannot be resolved on your classpath. You need to add the JAR file spring-context.jar
to your classpath.
精彩评论