5

Is Websphere 8.5.5 compatible with Spring 5? The Validation API referenced in spring5 (validation-api 5) is resulting in MethodNotFound exception.. Any pointers/patch available to get this solved - short of upgrading to Websphere 9?

Caused by: java.lang.NoSuchMethodError: javax/validation/Configuration.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider; (loaded from file:/opt/IBM/WebSphere/AppServer/plugins/javax.j2ee.validation.jar by org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@25d460de) called from class org.springframework.validation.beanvalidation.LocalValidatorFactoryBean (loaded from file:../spring-context-5.0.2.RELEASE.jar by com.ibm.ws.classloader.CompoundClassLoader@1c7dbdd9

Jebuselwyn Martin
  • 543
  • 1
  • 5
  • 18
  • This question and the answers refer only to the incompatibility related to validation-api, but I think that the main incompatibility is the one related to servlet-api: see https://stackoverflow.com/a/70803006/685806 – Pino Sep 26 '22 at 10:28

5 Answers5

6

The method javax/validation/Configuration.getDefaultParameterNameProvider was added in Bean Validation 1.1, so that indicates the Spring Validator you are using is attempting to use the Bean Validation 1.1 API. According to https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.html:

As of Spring 5.0, this class requires Bean Validation 1.1+

WebSphere 8.5.5 provides Bean Validation 1.0 and did not add support for Bean Validation 1.1 until version 9.0. So, you'll either need to use Spring 4.x or WebSphere 9.x.

Alex Motley
  • 430
  • 6
  • 12
5

The above answer is not correct. You can run Spring 5 in WebSphere 8.5. This may not be the perfect solution for your situation, but this will get you on the correct path.

1.) Provide your Bean Validation 1.1 JAR

Here is a sample of the Maven dependency.

<dependency>
    <groupId>javax.validation</groupId>
    <artifactId>validation-api</artifactId>
    <version>1.1.0.Final</version>
</dependency>

2.) Add the following a deployment.xml file to the following location in your EAR file.

/myAppEAR/META-INF/ibmconfig/cells/defaultCell/applications/defaultApp/deployments/defaultApp/deployment.xml

3.) In the contents of your deployment.xml file, you must set the classloaderMode to PARENT_LAST. You must also modify this code to use the correct WAR file name.

Here is a sample...

<appdeployment:Deployment xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:appdeployment="http://www.ibm.com/websphere/appserver/schemas/5.0/appdeployment.xmi" xmi:id="Deployment_1422578178899">
  <deployedObject xmi:type="appdeployment:ApplicationDeployment" xmi:id="ApplicationDeployment_1422578178899" startingWeight="10" warClassLoaderPolicy="SINGLE">
    <modules xmi:type="appdeployment:WebModuleDeployment" xmi:id="WebModuleDeployment_1422578178899" startingWeight="10000" **uri="myApp.war"** **classloaderMode="PARENT_LAST"**/>
    <classloader xmi:id="Classloader_1422578178899" **mode="PARENT_LAST"**/>
 </classloader>
  </deployedObject>
</appdeployment:Deployment>
Rob Breidecker
  • 604
  • 1
  • 7
  • 12
2

@rob-breidecker is correct, this is possible even though WebSphere 8.5.5 provides Bean Validation 1.0. To do this, you need to change the classloader of your application.

To do that via the UI, go to Applications -> WebSphere enterprise applications -> Your Application -> Class loading and update detection and change the Class loader order to be Classes loaded with local class loader first (parent last). This "causes the class loader to attempt to load classes from its local class path before delegating the class loading to its parent.".

If you are deploying an EAR and want this change to propagate to inner applications, you can either change WAR class loader policy to Single class loader for application or change the class loader of the individual war (in the EAR click Manage Modules -> Your Module then change Class loader order).

enter image description here

As long as you provide a version of validation-api (I used 2.0.1.Final), you should get passed the above issue.

The following wasadmin.sh script will apply the above settings (replace app_name with the name of your application): (credit)

dep = AdminConfig.getid('/Deployment:app_name/');
depObject = AdminConfig.showAttribute(dep, 'deployedObject');
AdminConfig.modify(depObject, [['warClassLoaderPolicy', 'SINGLE']]);
classldr = AdminConfig.showAttribute(depObject, 'classloader');
AdminConfig.modify(classldr, [['mode', 'PARENT_LAST']]);
Daniel Treiber
  • 1,411
  • 12
  • 9
1

I though at some point it was impossible to do this, but finally, I found a solution, you can use spring 5.X and Boot 2.X with WebShpre 8.5 using the below Steps, just make sure that you project is compatible with:

1- Bean Validation  
2- Servelt 3.1

Steps:

1- Create a custom folder on you server for example /opt/custom/lib/spring5 and upload below jars to this folder
    a. jakarta.el-3.0.4.jar
    b. jakarta.validation-api-2.0.2.jar

2- Create a new shared library in WebSphere as below 
    a. Go to environment -> shared library
    b. Chose the scope to node and server
    c. Click on New and fill the value with below
        i. Name: spring5
        ii. Class path: /opt/custom/lib/spring5
        iii. Enable checkbox  “use an isolated class loader for this shared library”
3- Restart the server
4- Go to Enterprise Application Click on the application (WAR/EAR)
5- Go To shared library reference add assign it to you application (WAR/EAR)
6- Go to Enterprise Application Click on the application (WAR/EAR)
7- Choose Classes loaded with local class loader first (parent last)
8- Restart the server
0

In case someone still needs a solution, the only way it worked for me was to change the file https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.html from 5.x to use the logic from 4.x

Cristi
  • 1