`
xjg396
  • 浏览: 46560 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

spring mvc 后台验证JSR-303 Validator

    博客分类:
  • java
阅读更多
Spring mvc 注解采用JSR-303 Validator 进行验证,
<bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
		<property name="messageConverters">
			<list>
				<bean class="org.springframework.http.converter.StringHttpMessageConverter">
					<property name="supportedMediaTypes">
						<list>
							<value>text/plain;charset=UTF-8</value>
						</list>
					</property>
				</bean>
			</list>
		</property>
		<!-- 验证框架配置 -->
		<property name="webBindingInitializer">
			<bean class="org.springframework.web.bind.support.ConfigurableWebBindingInitializer">
				<property name="validator" ref="validator" />
			</bean>
		</property>
	</bean>



jar包一定要用  hibernate-validator-4.0.0.Beta2.jar ,之前大意,用了hibernate-validator.jar , 程序一启动就报错。
2013-8-5 13:45:55 org.apache.catalina.core.StandardContext listenerStart
严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter#0' defined in file [D:\apache-tomcat-6.0.37\webapps\erp.myeclipse.bak\WEB-INF\classes\spring\applicationContext-servlet.xml]: Cannot create inner bean 'org.springframework.web.bind.support.ConfigurableWebBindingInitializer#38df00' of type [org.springframework.web.bind.support.ConfigurableWebBindingInitializer] while setting bean property 'webBindingInitializer'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.bind.support.ConfigurableWebBindingInitializer#38df00' defined in file [D:\apache-tomcat-6.0.37\webapps\erp.myeclipse.bak\WEB-INF\classes\spring\applicationContext-servlet.xml]: Cannot resolve reference to bean 'validator' while setting bean property 'validator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'validator' defined in file [D:\apache-tomcat-6.0.37\webapps\erp\WEB-INF\classes\spring\applicationContext-servlet.xml]: Invocation of init method failed; nested exception is javax.validation.ValidationException: Unable to find a default provider
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:281)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:120)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:580)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425)
	at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4206)
	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4705)
	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)
	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)
	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)
	at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)
	at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)
	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)
	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)
	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)
	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)
	at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)
	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)
	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)
	at org.apache.catalina.core.StandardService.start(StandardService.java:525)
	at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)
	at org.apache.catalina.startup.Catalina.start(Catalina.java:595)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.bind.support.ConfigurableWebBindingInitializer#38df00' defined in file [D:\apache-tomcat-6.0.37\webapps\erp\WEB-INF\classes\spring\applicationContext-servlet.xml]: Cannot resolve reference to bean 'validator' while setting bean property 'validator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'validator' defined in file [D:\apache-tomcat-6.0.37\webapps\erp.myeclipse.bak\WEB-INF\classes\spring\applicationContext-servlet.xml]: Invocation of init method failed; nested exception is javax.validation.ValidationException: Unable to find a default provider
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1325)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1086)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270)
	... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'validator' defined in file [D:\apache-tomcat-6.0.37\webapps\erp\WEB-INF\classes\spring\applicationContext-servlet.xml]: Invocation of init method failed; nested exception is javax.validation.ValidationException: Unable to find a default provider
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
	at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
	... 45 more
Caused by: javax.validation.ValidationException: Unable to find a default provider
	at javax.validation.Validation$GenericBootstrapImpl.configure(Validation.java:245)
	at org.springframework.validation.beanvalidation.LocalValidatorFactoryBean.afterPropertiesSet(LocalValidatorFactoryBean.java:183)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
	... 52 more

后来换下jar包就可以了。原由还不太清楚
分享到:
评论

相关推荐

    JSR-303接口标准和参考实现

    `hibernate-validator-4.2.0.Final.jar`是这个特定版本的Hibernate Validator的归档文件,包含了所有必要的类和库,使开发者能够在他们的项目中实现JSR-303验证。 `validation-api-1.0.0.GA.jar`是JSR-303验证API的...

    SpringMVC使用JSR-303进行验证Bean.docx

    SpringMVC框架结合JSR-303(也称为JSR-349,Java Bean Validation)规范提供了一种优雅的方式来处理数据验证。本篇文章将详细介绍如何在SpringMVC中使用JSR-303进行Bean验证。 首先,我们需要引入JSR-303的实现库。...

    JSR303依赖的jar包

    Spring MVC 3.x 之中也大力支持 JSR-303,可以在控制器中对表单提交的数据方便地验证。 该压缩包包含了hibernate-validator-5.2.4.Final.jar、hibernate-validator-annotation-processor-5.2.4.Final.jar、...

    spring_validator验证

    Spring MVC的`springmvc-validator`模块为开发者提供了强大的验证功能,结合JSR-303/349标准注解,可以轻松实现业务对象的验证。通过自定义Validator,我们可以根据具体需求扩展验证逻辑。正确处理验证错误,确保...

    springmvc使用JSR-303进行数据校验实例

    SpringMVC结合JSR-303可以实现对数据的有效验证,确保接收到的数据是符合业务要求的。接下来,我们会详细讲解如何在SpringMVC项目中集成JSR-303进行数据校验。 首先,我们来看如何集成JSR-303到SpringMVC项目中。...

    SpringMVC源码总结(二)mvc:mvc:annotation-driven背后的那些事

    `mvc:annotation-driven`会自动配置`LocalValidatorFactoryBean`,提供JSR-303/JSR-349的验证支持。 5. **异常处理**:Spring MVC提供了`@ExceptionHandler`注解来处理特定的运行时异常。`mvc:annotation-driven`会...

    Mastering Spring MVC 4(2015.09)源码

    Hibernate Validator或JSR-303/JSR-349规范的验证可以集成到模型属性的验证中,确保输入数据的有效性。 拦截器(Interceptor)是Spring MVC中的一种机制,可以在请求处理前、后执行自定义逻辑。通过实现...

    spirngmvc4适用的hibernate-validator后台验证的jar包,亲测可用

    Hibernate Validator,作为JSR 303和JSR 349(Bean Validation)的标准实现,为Java应用提供了强大的验证功能,它可以方便地与Spring MVC整合,实现模型数据的验证。 标题提到的"spirngmvc4适用的hibernate-...

    hibernate-validator-6.1.2.Final-dist.zip

    Hibernate Validator是JSR-303(Bean Validation)和JSR-349(Bean Validation 1.1)规范的参考实现,提供了一种标准的方式来验证Java对象的属性,确保输入数据的正确性和完整性。它支持注解驱动的验证,使得代码...

    hibernate-validator-4.1.0.Final.rar

    Hibernate Validator是Hibernate项目的一个重要组成部分,它是一个基于JSR-303(Bean Validation)规范的实现,提供了强大的Java Bean数据验证功能。这次我们关注的是Hibernate Validator的4.1.0.Final版本,该版本...

    SpringMVC 使用JSR-303进行校验 @Valid示例

    JSR-303是Java Specification Requests之一,是一种用于Java的Bean验证规范。它定义了一套元数据模型和API,用于在Java Bean上进行声明式验证。 使用SpringMVC结合JSR-303进行数据校验的流程一般包括以下几个步骤:...

    Spring MVC简单例子

    Spring MVC可以通过自定义Validator或使用JSR-303/JSR-349 Bean Validation进行验证。同时,安全方面需要考虑防止SQL注入和XSS攻击。 7. **视图解析器**:设置ViewResolver,如InternalResourceViewResolver,用来...

    hibernate-validator-5.2.1.Final-dist

    Hibernate Validator 是 Hibernate 社区提供的一款强大的Java Bean验证框架,它基于JSR-303(Bean Validation)标准,为开发者提供了便捷的验证API,使得数据验证过程更为高效且易于维护。本文将深入探讨Hibernate ...

    ssm中hibernate-validator后台注册验证

    在这个项目中,我们关注的是`Hibernate-Validator`,它是JSR 303/JSR 349标准的实现,用于提供后台验证功能。`Hibernate-Validator`使得在SSM框架中对用户输入的数据进行校验变得更加方便和规范。 首先,我们需要...

    spring-mvc实例

    Spring MVC 3引入了许多新特性,比如支持JSR-303的bean验证,改进的类型转换系统,以及对异步处理的支持。通过学习这个实例,你可以更好地理解Spring MVC的工作原理,掌握其核心概念,并能将其应用于实际项目中。

    hibernate-validator-4.0.1.GA-dist

    Hibernate Validator 是基于 JSR-303(Java Bean Validation)和 JSR-349(Java Bean Validation 1.1)规范的实现,它提供了一套灵活且强大的验证API,使得开发者能够对对象属性进行校验,确保输入数据的正确性。...

    Spring MVC的所有jar包

    对于数据绑定和验证,`hibernate-validator.jar`和`validation-api.jar`提供了JSR-303/JSR-349标准的实现,允许在控制器方法中对参数进行验证。 此外,还有可能包含其他依赖,如JSON处理库(如`jackson-databind....

    Springmvc数据验证6个详细包,hibernate-validator-5.1.3.Final.jar...

    `hibernate-validator-5.1.3.Final.jar` 文件是Hibernate Validator的一个特定版本,用于在Spring MVC中进行数据验证。 1. **数据验证的基本概念**:数据验证是为了确保用户输入或者系统间交互的数据满足业务规则,...

    SpringMVC之DataBinding和Validation--Validator,PropertyEditor,Converter,Formatter

    在Java世界中,Bean Validation(JSR 303/349)提供了一种标准的方式来验证对象的属性。Spring MVC通过集成Hibernate Validator(Bean Validation的实现),使得我们可以方便地对请求数据进行验证。我们可以在模型类...

    spring-webmvc-4.1.2

    同时,利用Hibernate Validator或JSR-303/JSR-349标准,可以方便地进行数据验证。 7. **拦截器**:通过实现HandlerInterceptor接口,开发者可以创建自定义拦截器,执行预处理和后处理操作,如登录检查、性能监控等...

Global site tag (gtag.js) - Google Analytics