我试图部署一个Spring启动应用程序使用2.6.2IBMWebSphere8.5.5.20(使用java8)
为了测试这个问题,我尝试部署一个简单的Hello World rest控制器,并面临以下问题。我能够在WebSphere8.5.5.20上使用Spring Boot 1.5部署应用程序,但在迁移到spring-boot 2.6.2时遇到困难。
请注意,我已经尝试了javax. servlet和jakarta.servlet(版本根据Spring Boot依赖项)。我遵循了这个链接[https://stackoverflow.com/questions/48156126/websphere-8-5-with-spring-5],在WebSphere 8.5.5上部署Spring Boot 2.x应用程序
根据我如何通过从企业应用程序设置应用程序的类加载器,我收到以下错误
家长最后
错误:
[1/7/22 16:39:57:407 EST] 00000001 ContainerHelp E WSVR0501E: Error creating component com.ibm.ws.runtime.component.CompositionUnitMgrImpl@c412fa58
com.ibm.ws.exception.RuntimeWarning: com.ibm.ws.exception.RuntimeWarning: com.ibm.ws.webcontainer.exception.WebAppNotLoadedException: Failed to load webapp: Failed to load webapp: javax.servlet.ServletContainerInitializer: Provider ch.qos.logback.classic.servlet.LogbackServletContainerInitializer not a subtype
家长优先
错误:
[1/7/22 16:42:17:173 EST] 00000047 SystemOut O 2022-01-07 16:42:17.173 WARN 31546 --- [ver.startup : 1] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'defaultValidator' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: javax/validation/Configuration.getDefaultParameterNameProvider()Ljavax/validation/ParameterNameProvider; (loaded from file:/xxxxxxx/was/INSTANCE1/plugins/javax.j2ee.validation.jar by org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@25be5b0d) called from class org.springframework.validation.beanvalidation.LocalValidatorFactoryBean (loaded from file:xxxx/simple-boot.ear/simple-boot.war/WEB-INF/lib/spring-context-5.3.14.jar by
com.ibm.ws.classloader.CompoundClassLoader@24768f5e[war:simple-boot/simple-boot.war]
我的pom. xml
注意:在这个pom. xml中,我有javax.servlet使用3.1.0进行测试,但如上所述,根据Spring Boot依赖项尝试了默认版本,结果也相同。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.my.testApp</groupId>
<artifactId>simple-webapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>simple-boot</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<exclusions>
<exclusion>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
<build>
<finalName>simple-boot</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
根据错误消息,父版本看起来失败了,因为您的应用程序中打包了ServletAPI的副本。这不是一个可用的配置,因为容器将链接到它自己的API副本,因此它将无法成功转换链接到它们自己的API实例的应用程序工件。有一些API,您可以在应用程序中引入自己的版本,但Servlet不在其中。
对于父级优先的失败,看起来Spring期待一个比服务器提供的javax.验证包更新的版本——它调用的是服务器版本中不存在的方法。WebSphere8.5.5实现了JavaEE6,其中包括BeanValidation1.0,并且该方法直到BeanValidation1.1才被添加。您将需要一个与JavaEE6一起工作的Spring版本,或者可配置以避免更高版本的依赖。也可以通过运行父辈最后并包含一个单独的实现以及API(显然,删除上一段中引用的ServletAPI)来解决这个问题,尽管我对Bean验证不够熟悉API知道这是否会像Servlet一样导致与服务器运行时的冲突。