I have a legacy Spring application to maintain. The application uses spring framework and spring beanutils. I am upgrading to 4.x. However, when I run on jetty, I find this error
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)
I found that the function ClassUtils.forName(String) is deprecated in SpringFraemwork 3 and not there anymore in 4.
Can I find a newer replacement for the springmodules validation jar 0.9.0?
A new one should not call this function and should call ClassUtils.forName(String, ClassLoader).
Is it included in new Spring jars?
I noticed something called Hibernate-validator and I am not sure this could help or not.
Its been a year but I am answering it considering if anyone still may need the solution. Recently I have replaced spring-modules-validation using Bean Validation 1.0 (JSR-303) and Bean Validation 1.1 (JSR-349) in my application as a alternate solution. My application is using Spring Framework 4. I have replaced the dependency of spring-modules-validation with javax.validation:validation-api and org.hibernate.validator:hibernate-validator.
Regarding implementation , it depends what are the bean validator you want to replace e.g @Length
of org.springmodules.validation.bean.conf.loader.annotation.handler.Length
can be replaced with @Size
of javax.validation.constraints.Size
.Similarly @NotBlank
of org.springmodules.validation.bean.conf.loader.annotation.handler.NotBlank
can be replaced by @NotBlank
of javax.validation.constraints.NotBlank
etc. You can create validator bean using class org.springframework.validation.beanvalidation.LocalValidatorFactoryBean
instead of org.springmodules.validation.bean.BeanValidator
.
Please note that these are just some of the annotations available in JSR 303. In addition Hibernate Validator introduces a few of its own. Please find spring documentation here