com.springsource.org.springmodules.validation.validator 0.9.0 是否有更新的替代品?

is there an updated replacement for com.springsource.org.springmodules.validation.validator 0.9.0?

我有一个遗留 Spring 应用程序需要维护。 该应用程序使用 spring 框架和 spring beanutils。我正在升级到 4.x。 但是,当我 运行 在码头上时,我发现这个错误

java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava/lang/String;)Ljava/lang/Class;
at org.springmodules.validation.util.LibraryUtils.isClassInClasspath(LibraryUtils.java:56)
at org.springmodules.validation.util.LibraryUtils.<clinit>(LibraryUtils.java:30)
at org.springmodules.validation.bean.conf.loader.annotation.DefaultValidationAnnotationHandlerRegistry.<init>(DefaultValidationAnnotationHandlerRegistry.java:115)
at org.springmodules.validation.bean.conf.loader.annotation.AnnotationBeanValidationConfigurationLoader.<init>(AnnotationBeanValidationConfigurationLoader.java:82)
at org.springmodules.validation.bean.conf.loader.annotation.AnnotationBeanValidationConfigurationLoader.<init>(AnnotationBeanValidationConfigurationLoader.java:69)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:142)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1147)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1099)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:513)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:761)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:443)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:325)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:835)
at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:530)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:808)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:342)
at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1379)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1341)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:772)
at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:259)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:517)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:132)
at org.eclipse.jetty.server.Server.start(Server.java:405)
at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:106)
at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)
at org.eclipse.jetty.server.Server.doStart(Server.java:372)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)
at runjettyrun.Bootstrap.main(Bootstrap.java:89)

我发现函数 ClassUtils.forName(String) 在 SpringFraemwork 3 中已弃用,而在 4 中不再存在。

我能找到 springmodules validation jar 0.9.0 的更新替代品吗?

新手不要调用这个函数,应该调用ClassUtils.forName(String, ClassLoader).

它是否包含在新的 Spring 罐子中?

我注意到一个叫做 Hibernate-validator 的东西,我不确定这是否有帮助。

已经一年了,但考虑到是否还有人可能需要解决方案,我正在回答它。 最近我用 Bean Validation 1.0 (JSR-303)Bean Validation 1.1 (JSR-349)[=32= 替换了 spring-modules-validation ] 在我的应用程序中作为替代解决方案。我的应用程序正在使用 Spring Framework 4。我已将 spring-modules-validation 的依赖项替换为 javax.validation:validation -apiorg.hibernate.validator:hibernate-validator.

关于实现,这取决于您要替换的 bean 验证器是什么,例如 org.springmodules.validation.bean.conf.loader.annotation.handler.Length@Length 可以替换为 javax.validation.constraints.Size@Size。类似地 [= org.springmodules.validation.bean.conf.loader.annotation.handler.NotBlank 的 14=] 可以替换为 javax.validation.constraints.NotBlank@NotBlank 等。您可以使用 class org.springframework.validation.beanvalidation.LocalValidatorFactoryBean 而不是 org.springmodules.validation.bean.BeanValidator 创建验证器 bean。

请注意,这些只是 JSR 303 中可用的部分注释。此外,Hibernate Validator 还引入了一些它自己的注释。请查找 spring 文档 here