Spring Boot and Spring Module Validator throws java.lang.NoSuchMethodError - spring

I am migrating my old project to Spring Boot 1.3.5. The project has Spring Modules Validation 0.8. But spring-modules-validation (which is no more active) does not work. And throws following exception.
Caused by: java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava/lang/String;)Ljava/lang/Class;
at org.springmodules.validation.valang.parser.ValangParser.loadClass(ValangParser.java:130)
at org.springmodules.validation.valang.parser.ValangParser.setFunctionsByName(ValangParser.java:105)
at org.springmodules.validation.valang.parser.ValangParser.<init>(ValangParser.java:55)
at org.springmodules.validation.valang.parser.SimpleValangBased.createValangParser(SimpleValangBased.java:77)
at org.springmodules.validation.valang.ValangValidator.afterPropertiesSet(ValangValidator.java:159)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
I have already followed some of old threads on similar issue. But those are not directly related to the versions I am using. This is how my related pom looks like.
<dependency>
<groupId>org.springmodules</groupId>
<artifactId>spring-modules-validation</artifactId>
<version>0.8</version>
<exclusions>
<exclusion>
<artifactId>spring</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
</exclusion>
</exclusions>
</dependency>

Related

Springfox swagger2 without Spring Boot (Spring-web 4.3.22)

I am trying to use Springfox Swagger 2 with a non-SpringBoot Spring application (Spring-web MVC), using Spring-web 4.3.22-RELEASE. However when I include the following dependency
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
In my pom.xml, without adding any code to use it or anything like that, my 'maven install' starts failing. The error I see is.
Caused by: java.lang.NoClassDefFoundError: org/springframework/context/event/EventListenerFactory
Caused by: java.lang.ClassNotFoundException: org.springframework.context.event.EventListenerFactory
I think that that is a Spring 5 Class, and I can't figure out how to get it to work with this older verison. Things I've tried:
Add org.webjars:bootstrap as a dependency as well
Decrease the version of springfox-swagger2 I'm using, all the way to 2.0.1. I also tried changing to swagger1 with no success
Note: I have the Jackson Databind dependency mentioned in A 'simple' way to implement Swagger in a Spring MVC application
Relevant parts of POM (its hard to post the entire POM as we have a sophisticated hierarchy, sorry for the formatting)
<properties>
<jackson.databind.version>2.9.8</jackson.databind.version>
<spring.version>4.3.22.RELEASE</spring.version>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.databind.version}</version>
</dependency>

Using Spring Boot 2.0 with Tomcat 7.0.82

I have a project that uses Spring Boot 2.0.0.RC2. I need to deploy it to a customer environment using traditional deployment for Tomcat 7.0.82.
I've managed to build a war that can be deployed successfully by configuring web.xml in a typical way for Spring applications (with DispatcherServlet) instead of using SpringBootServletInitializer.
I also would like to have a quick way of starting the app on local environment using an embedded Tomcat container by simply running the main method in the application class with #SpringBootApplication annotation. It works fine if I'm using the default Tomcat version (8.5.28). However, I would like to start the embedded container also in 7.0.82 version. This is important for me for another reason - I'm using SpringBootTest and it would be nice if those tests run on the exact same container as the customer environment. Unfortunately, I can't use the Spring Boot parent POM and override tomcat.version property.
I've tried #SpringBootApplication(exclude = ServletWebServerFactoryAutoConfiguration.class) create TomcatServletWebServerFactory bean manually
#Bean
public ServletWebServerFactory tomcatServletWebServerFactory() {
return new TomcatServletWebServerFactory();
}
and add tomcat 7.0.82 dependencies explicitly in pom.xml (${tomcat.version} = 7.0.82):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-annotations-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-annotations-api</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-util</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-el</artifactId>
<version>${tomcat.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-websocket</artifactId>
<version>${tomcat.version}</version>
</dependency>
but I'm still getting a java.lang.NoClassDefFoundError: org/apache/tomcat/util/scan/StandardJarScanFilter error.
Could you please advise if there is any way to meet my requirements?
Spring boot 2:
The minimum supported version of Tomcat is 8.5
Reference: https://dzone.com/articles/spring-boot-20-new-features-infrastructure-changes

Spring MVC 4 - Tiles3 - Tiles-extras dependency crashes applicaiton

I have an application up and working using Spring Boot (Maven). Currently configured as WAR with Stand Alone Tomcat. Everything works fine.
If I add tiles-extras v3.0.5 the application will crash with the following error. I am not using FreeMarker in the application. JSP & Tiles Only.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.boot.autoconfigure.freemarker.FreeMarkerAutoConfiguration': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Cannot find template location(s): [classpath:/templates/] (please add some templates, check your FreeMarker configuration, or set spring.freemarker.checkTemplateLocation=false)
EDIT Adding viewResolver incase it is needed.
#Bean
public UrlBasedViewResolver viewResolver() {
UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
viewResolver.setViewClass(TilesView.class);
viewResolver.setOrder(0);
return viewResolver;
}
Change Implemented
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>${tiles.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-freemarker</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-velocity</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-request-mustache</artifactId>
</exclusion>
</exclusions>
</dependency>
New Error
Caused by: java.lang.NoClassDefFoundError: javax/servlet/jsp/JspFactory
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.5</version>
</dependency>
When adding tiles-extras as a dependency this automatically adds a lot of other tiles-* dependencies, see the pom. You might either want to exclude freemarker or the tiles-freemarker dependency.
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.5</version>
<exclusions>
<exclusion>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-freemarker</artifactId>
</exclusion>
</exclusions>
</dependency>
If you aren't using template engines you also might want to exclude the velocity dependency.

Spring webservice integration dependency issue with broadleaf

I create a e-commerce site by using the broadleaf framework. My broadleaf having following spring jar dependencies.
Also i want to add some Spring web service implementations with my broadleaf application. So i added spring-ws-core dependencies also broadleaf pom.xml (pom.xml under site).
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
The above dependencies become dependents with spring 3.2.4. I cant find out a spring-ws-core version which exactly matches the broadleaf spring dependency version (3.2.9) thats why i added the above dependency.
But when i run the application by adding the dependency i got the following exception
java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata.needsRefresh(Lorg/springframework/beans/factory/annotation/InjectionMetadata;Ljava/lang/Class;)Z
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.findPersistenceMetadata(PersistenceAnnotationBeanPostProcessor.java:368)
at org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor.postProcessMergedBeanDefinition(PersistenceAnnotationBeanPostProcessor.java:323)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyMergedBeanDefinitionPostProcessors(AbstractAutowireCapableBeanFactory.java:840)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:495)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:198)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:741)
at org.springframework.context.support.AbstractApplicationContext.__refresh(AbstractApplicationContext.java:464)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
at org.broadleafcommerce.common.web.extensibility.MergeContextLoaderListener.contextInitialized(MergeContextLoaderListener.java:50)
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4779)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5273)
Also i tried with the next version dependency
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.2.0.RELEASE</version>
</dependency>
Here i got class not found exception currosponding to org.springframework.beans.factory.config.ListFactoryBean
Is there is any idea to resolve this issue?
Because of the Spring dependency collisions, you will need to make sure that when you bring in the spring-ws-core dependency you are excluding all of the Spring transitive dependencies:
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>2.2.0.RELEASE</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<artifactId>spring-aop</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>

java.lang.ClassNotFoundException: org.springframework.web.util.ExpressionEvaluationUtils

I just upgraded a Spring MVC application, version 3.2 to a 4.0.2 and my view tags are not working anymore.
The error:
java.lang.ClassNotFoundException: org.springframework.web.util.ExpressionEvaluationUtils
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
org.springframework.web.servlet.tags.MessageTag.resolveMessage(MessageTag.java:215)
org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:166)
org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
org.apache.jsp.views.templates.main_jsp._jspx_meth_spring_005fmessage_005f0(main_jsp.java:570)
The class ExpressionEvaluationUtils was deprecated in Spring 3.2 and removed in 4.x.
I'm running Tomcat 7.0.50 using Eclipse IDE.
What am i missing here?
Belo are some parts of my configuration.
<java-version>1.7</java-version>
<org.springframework-version>4.0.2.RELEASE</org.springframework-version>
<spring-security.version>3.2.1.RELEASE</spring-security.version>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<artifactId>spring-aop</artifactId>
<groupId>org.springframework</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
If you haven't changed you JSPs when upgrading spring then you may have old compiled JSPs from the old spring version (the .tags.MessageTag. thing in you stacktrace). Clear your tomcat work directory to recompile the JSPs and try again.
You also need to update the spring-security dependencies to 4.0.n.RELEASE versions.
I just found out that you need to change the jsp-config web.xml to ignore-el = true.
It works now.
<jsp-config>
<jsp-property-group>
<url-pattern>/**</url-pattern>
<el-ignored>**true**</el-ignored>
</jsp-property-group>
</jsp-config>

Resources