Websphere 8.5 与 Spring-5

Websphere 8.5 with Spring-5

Websphere 8.5.5 与 Spring 5 兼容吗? spring5 中引用的验证 API (validation-api 5) 导致 MethodNotFound 异常。任何 pointers/patch 可用于解决此问题 - 升级到 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

方法 javax/validation/Configuration.getDefaultParameterNameProvider 是在 Bean Validation 1.1 中添加的,因此这表明您正在使用的 Spring Validator 正在尝试使用 Bean Validation 1.1 API。根据 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 提供了 Bean Validation 1.0,直到 9.0 版本才添加对 Bean Validation 1.1 的支持。因此,您需要使用 Spring 4.x 或 WebSphere 9.x.

以上回答不正确。您可以 运行 Spring 5 在 WebSphere 8.5 中。对于您的情况,这可能不是完美的解决方案,但这会让您走上正确的道路。

1.) 提供您的 Bean Validation 1.1 JAR

这是 Maven 依赖项的示例。

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

2.) 将以下 deployment.xml 文件添加到 EAR 文件中的以下位置。

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

3.) 在 deployment.xml 文件的内容中,您必须将 classloaderMode 设置为 PARENT_LAST。您还必须修改此代码以使用正确的 WAR 文件名。

这是一个示例...

<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 是正确的,即使 WebSphere 8.5.5 提供了 Bean Validation 1.0,这也是可能的。为此,您需要更改应用程序的 classloader。

要通过 UI 执行此操作,请转至 Applications -> WebSphere enterprise applications -> 你的应用程序 -> Class加载和更新检测并将Class加载器顺序更改为是 Classes 首先用本地 class 加载器加载(父最后)。这个"causes the class loader to attempt to load classes from its local class path before delegating the class loading to its parent."

如果您正在部署 EAR 并希望此更改传播到内部应用程序,您可以将 WAR class 加载程序策略 更改为 应用程序的单个class加载程序或更改单个class加载程序war(在EAR中单击管理模块 -> 您的模块 然后更改 Class 加载器顺序)。

只要提供validation-api的版本即可(我用的是2.0.1.Final ), 你应该通过了上面的问题。

以下 wasadmin.sh 脚本将应用上述设置(将 app_name 替换为您的应用程序名称):(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']]);

如果有人仍然需要解决方案,唯一对我有用的方法就是更改文件 https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/validation/beanvalidation/LocalValidatorFactoryBean.html 来自 5.x 以使用来自 4.x

的逻辑

我虽然在某些时候不可能做到这一点,但最后,我找到了一个解决方案,您可以使用 spring 5.X 和 Boot 2.X 与 WebShpre 8.5 使用在步骤下方,只需确保您的项目兼容:

1- Bean Validation  
2- Servelt 3.1

步骤:

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