Weblogic + Spring 启动云 Eureka 服务器

Weblogic + Spring Boot Cloud Eureka Server

我正在尝试 运行 Spring 在 Weblogic 网络服务器(Java 8、Weblogic 12 和 Spring 引导父 2.4.13 下启动 Cloud Eureka 服务器).我将我的 pom 配置为生成一个 war 文件并且我能够部署但是,一旦它启动我就会收到这些错误:

2022-03-03 18:46:34.013 ERROR 5108 --- [ (self-tuning)'] o.s.b.d.LoggingFailureAnalysisReporter   :

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration.jerseyFilterRegistration(EurekaServerAutoConfiguration.java:185)

The following method did not exist:

    com.sun.jersey.spi.container.servlet.ServletContainer.<init>(Ljavax/ws/rs/core/Application;)V

The method's class, com.sun.jersey.spi.container.servlet.ServletContainer, is available from the following locations:

    zip:D:/Development/Domains/lifeGateway/servers/AdminServer/tmp/_WL_user/registrationServer/rh50eu/war/WEB-INF/lib/jersey-servlet-1.19.4.jar!/com/sun/jersey/spi/container/servlet/ServletContainer.class
    jar:file:/D:/Development/Servers/WebLogic12213/wls12213/oracle_common/modules/weblogic.jaxrs.portable.server.jar!/com/sun/jersey/spi/container/servlet/ServletContainer.class

The class hierarchy was loaded from the following locations:

    com.sun.jersey.spi.container.servlet.ServletContainer: file:/D:/Development/Servers/WebLogic12213/wls12213/oracle_common/modules/weblogic.jaxrs.portable.server.jar
    javax.servlet.http.HttpServlet: file:/D:/Development/Servers/WebLogic12213/wls12213/oracle_common/modules/javax.servlet.javax.servlet-api.jar
    javax.servlet.GenericServlet: file:/D:/Development/Servers/WebLogic12213/wls12213/oracle_common/modules/javax.servlet.javax.servlet-api.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of com.sun.jersey.spi.container.servlet.ServletContainer

<Mar 3, 2022 6:46:34,271 PM CET> <Error> <Deployer> <BEA-149265> <Failure occurred in the execution of deployment request with ID "1291493286977307" for task "2" on [partition-name: DOMAIN]. Error is: "weblogic.application.ModuleException: java.lang.NoSuchMethodError: com.sun.jersey.spi.container.servlet.ServletContainer.<init>(Ljavax/ws/rs/core/Application;)V"
weblogic.application.ModuleException: java.lang.NoSuchMethodError: com.sun.jersey.spi.container.servlet.ServletContainer.<init>(Ljavax/ws/rs/core/Application;)V
        at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
        at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
        at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:233)
        at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:228)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodError: com.sun.jersey.spi.container.servlet.ServletContainer.<init>(Ljavax/ws/rs/core/Application;)V
        at org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration.jerseyFilterRegistration(EurekaServerAutoConfiguration.java:185)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        Truncated. see log file for complete stacktrace
>
<Mar 3, 2022 6:46:34,315 PM CET> <Error> <Deployer> <BEA-149202> <Encountered an exception while attempting to commit the 1 task for the application "registrationServer" on [partition-name: DOMAIN].>
<Mar 3, 2022 6:46:34,327 PM CET> <Warning> <Deployer> <BEA-149004> <Failures were detected while initiating deploy task for application "registrationServer".>
<Mar 3, 2022 6:46:34,327 PM CET> <Warning> <Deployer> <BEA-149078> <Stack trace for message 149004
weblogic.application.ModuleException: java.lang.NoSuchMethodError: com.sun.jersey.spi.container.servlet.ServletContainer.<init>(Ljavax/ws/rs/core/Application;)V
        at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
        at weblogic.application.internal.flow.ModuleListenerInvoker.start(ModuleListenerInvoker.java:124)
        at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:233)
        at weblogic.application.internal.flow.ModuleStateDriver.next(ModuleStateDriver.java:228)
        at weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:45)
        Truncated. see log file for complete stacktrace
Caused By: java.lang.NoSuchMethodError: com.sun.jersey.spi.container.servlet.ServletContainer.<init>(Ljavax/ws/rs/core/Application;)V
        at org.springframework.cloud.netflix.eureka.server.EurekaServerAutoConfiguration.jerseyFilterRegistration(EurekaServerAutoConfiguration.java:185)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        Truncated. see log file for complete stacktrace```

After some investigations, I start to think it is related to the embedded tomcat but, I am not sure. At the moment I am stuck, do you have any idea why I am getting this error? 

These are the dependencies I am including:

```<dependencies>

        <!-- 1. Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <!-- 2. Spring Boot Starter Cloud -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcprov-jdk15on</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- 3. Spring Boot Starter Web -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <!-- 4. Spring Boot Starter Modules -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <!-- 5. Servlet Starter -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>```

  1. 您必须确保您的目标包装类型是 war。查看您的 pom.xml
  2. 添加ServletInitializer
public class ServletInitializer extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootWebLogicApplication.class);
    }

}
  1. 添加 spring-boot-starter-tomcat 作为 provided 依赖关系
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

这些应该足够了。

我认为要使用 weblogic,需要将两个文件放在 WEB-INF

  1. weblogic.xml
  2. dispatcherServlet-servlet.xml

weblogic的内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<wls:weblogic-web-app
    xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://xmlns.oracle.com/weblogic/weblogic-web-app
    http://xmlns.oracle.com/weblogic/weblogic-web-app/1.4/weblogic-web-app.xsd">

<wls:context-root>/myweb</wls:context-root>
<wls:container-descriptor>
    <wls:prefer-application-packages>
        <wls:package-name>org.slf4j.*</wls:package-name>
        <wls:package-name>org.springframework.*</wls:package-name>
    </wls:prefer-application-packages>
</wls:container-descriptor>
</wls:weblogic-web-app>

dispatcherServlet-servlet.xml内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

</beans>

我终于找到问题了。为了在 Weblogic 下启动 Eureka 服务,必须解决一些依赖冲突(特别是 Jersey 和 FasterXml Jackson deps)。

所以,我把 pom.xml 改成了这样:

<dependencyManagement>
<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>${spring-cloud.version}</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>
</dependencies>
<!-- 1. Spring Boot -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter</artifactId>
</dependency>

<!-- 2. Spring Boot Starter Cloud -->
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk15on</artifactId>
        </exclusion>
        <exclusion>
            <artifactId>jersey-core</artifactId>
            <groupId>com.sun.jersey</groupId>
        </exclusion>
        <exclusion>
            <artifactId>jersey-client</artifactId>
            <groupId>com.sun.jersey</groupId>
        </exclusion>
        <exclusion>
            <artifactId>woodstox-core</artifactId>
            <groupId>com.fasterxml.woodstox</groupId>
        </exclusion>
    </exclusions>
</dependency>

<!-- https://mvnrepository.com/artifact/com.netflix.eureka/eureka-client -->
<dependency>
    <groupId>com.netflix.eureka</groupId>
    <artifactId>eureka-client</artifactId>
    <version>1.10.17</version>
    <exclusions>
        <exclusion>
            <artifactId>jersey-client</artifactId>
            <groupId>com.sun.jersey</groupId>
        </exclusion>
        <exclusion>
            <artifactId>jersey-core</artifactId>
            <groupId>com.sun.jersey</groupId>
        </exclusion>
        <exclusion>
            <artifactId>guava</artifactId>
            <groupId>com.google.guava</groupId>
        </exclusion>
        <exclusion>
            <artifactId>servo-core</artifactId>
            <groupId>com.netflix.servo</groupId>
        </exclusion>
    </exclusions>
</dependency>


<!-- 3. Spring Boot Starter Web -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!-- 4. Spring Boot Starter Modules -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web-services</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
</dependency>
<dependency>
    <groupId>com.github.ben-manes.caffeine</groupId>
    <artifactId>caffeine</artifactId>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

<!-- 5. Servlet Starter -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

<!-- 6. Resolving conflicts with dependecies -->
<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-core</artifactId>
    <version>${com.sun.jersey}</version>
</dependency>

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-client</artifactId>
    <version>${com.sun.jersey}</version>
</dependency>

<dependency>
    <artifactId>jackson-dataformat-xml</artifactId>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <version>${jackson-dataformat-xml}</version>
    <exclusions>
        <exclusion>
            <artifactId>woodstox-core</artifactId>
            <groupId>com.fasterxml.woodstox</groupId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>${com.fasterxml.jackson}</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
    <version>${com.fasterxml.jackson}</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-annotations</artifactId>
    <version>${com.fasterxml.jackson}</version>
</dependency>

<dependency>
    <groupId>com.fasterxml.woodstox</groupId>
    <artifactId>woodstox-core</artifactId>
    <version>${com.fasterxml.woodstox}</version>
</dependency>

<dependency>
    <groupId>com.netflix.servo</groupId>
    <artifactId>servo-core</artifactId>
    <version>${com.netflix.servo}</version>
</dependency>