You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot 2.x部署WebLogic12.1.3遇springdoc依赖报错,需保留Swagger UI方案

解决方案:Spring Boot 2.x + springdoc 部署 WebLogic 12.1.3 冲突问题

针对引入springdoc依赖后部署WebLogic失败的问题,可通过以下方式解决:

1. 排除springdoc中与WebLogic冲突的依赖

springdoc依赖包中包含WebLogic已自带的组件(如servlet-api、tomcat-embed-core),版本冲突会导致部署失败。添加依赖排除:

<dependency>
    <groupId>org.springdoc</groupId>
    <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
    <version>2.0.0</version>
    <exclusions>
        <exclusion>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
        </exclusion>
        <exclusion>
            <groupId>org.apache.tomcat.embed</groupId>
            <artifactId>tomcat-embed-core</artifactId>
        </exclusion>
    </exclusions>
</dependency>

2. 配置WebLogic类加载优先级

WebLogic默认采用父类加载器优先,会导致springdoc的新类被WebLogic旧版本覆盖。创建或修改src/main/webapp/WEB-INF/weblogic.xml,设置优先加载应用自身的类:

<?xml version="1.0" encoding="UTF-8"?>
<weblogic-web-app xmlns="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.7/weblogic-web-app.xsd">
    <prefer-web-inf-classes>true</prefer-web-inf-classes>
</weblogic-web-app>

若不想全局开启,可改用精细包配置,只指定springdoc相关包优先加载:

<prefer-application-packages>
    <package-name>org.springdoc.*</package-name>
    <package-name>io.swagger.*</package-name>
    <package-name>com.fasterxml.jackson.*</package-name>
</prefer-application-packages>

3. 调整springdoc配置适配WebLogic

在application.properties中添加以下配置,确保静态资源和API文档能被WebLogic正确映射:

# 启用swagger-ui和api-docs
springdoc.swagger-ui.enabled=true
springdoc.api-docs.enabled=true
# 配置swagger-ui访问路径,避免WebLogic路径拦截
springdoc.swagger-ui.path=/swagger-ui.html
# 关闭Spring Boot默认静态资源处理,交由WebLogic处理
spring.web.resources.add-mappings=false

4. 配置WebLogic静态资源访问映射

修改src/main/webapp/WEB-INF/web.xml,添加静态资源的servlet映射,确保swagger-ui的资源能被正常访问:

<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/swagger-ui/*</url-pattern>
    <url-pattern>/v3/api-docs/*</url-pattern>
</servlet-mapping>

完成以上配置后,重新打包部署WebLogic,即可正常加载springdoc并访问swagger-ui。

内容的提问来源于stack exchange,提问作者Kiran Y

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.08 21:33:16