我有一个传统的Spring应用程序需要维护。 该应用程序使用spring框架和spring beanutils。我升级到4.x. 但是,当我在jetty上运行时,我发现了这个错误
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$1.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)。
它是否包含在新的春季罐中?
我发现了一些名为Hibernate-validator的东西,我不确定这可能会有所帮助。
答案 0 :(得分:1)
已经一年了,但是我正在回答,考虑是否有人仍然需要解决方案。 最近,我在应用程序中使用 Bean Validation 1.0(JSR-303)和 Bean Validation 1.1(JSR-349)替代了spring-modules-validation作为替代解决方案。我的应用程序使用的是Spring Framework4。我已将 spring-modules-validation 的依赖项替换为 javax.validation:validation-api 和 org.hibernate.validator :hibernate-validator 。
关于实现,这取决于您要替换的bean验证程序,例如@Length
的{{1}}可以被org.springmodules.validation.bean.conf.loader.annotation.handler.Length
的{{1}}替换。类似{{1} @Size
的}可以替换为javax.validation.constraints.Size
的{{1}}等。您可以使用类@NotBlank
而不是org.springmodules.validation.bean.conf.loader.annotation.handler.NotBlank
创建验证器bean。
请注意,这些只是JSR 303中可用的一些注释。此外,Hibernate Validator引入了一些自己的注释。请找到春季文档here