【问题标题】:SpringFox Swagger not working as expected on IBM Liberty 19.0.0.1SpringFox Swagger 在 IBM Liberty 19.0.0.1 上无法按预期工作
【发布时间】:2019-03-09 06:18:15
【问题描述】:

附在下面(Tomcat 上的 Swagger)(点击放大)- 我的应用程序在 Tomcat 9 上的 Swagger UI

附加(Liberty 上的 Swagger)(点击放大)- 我的应用程序在 Liberty 19.0.0.1 上的 Swagger UI

在 Tomcat 中,可以看出,200 响应体清晰显示,“Try it out”选项的执行完美无缺。

但是,在 Liberty 中,未显示 200 响应正文,并且“试用”执行会导致响应正文充满错误,如下所示(截断):

<H1>Error Page Exception</H1>
<H4>SRVE0260E: The server cannot use the error page specified for your application to handle the Original Exception printed below.</H4>
<BR><H3>Original Exception: </H3>
<B>Error Message: </B>Unauthorized<BR>
<B>Error Code: </B>401<BR>
<B>Target Servlet: </B>dispatcherServlet<BR>
<B>Error Stack: </B><BR>
com.ibm.ws.webcontainer.webapp.WebAppErrorReport: Unauthorized

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at com.ibm.ws.webcontainer.webapp.WebAppDispatcherContext.sendError(WebAppDispatcherContext.java:630)

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at com.ibm.ws.webcontainer.webapp.WebAppDispatcherContext.sendError(WebAppDispatcherContext.java:648)

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at com.ibm.ws.webcontainer.srt.SRTServletResponse.sendError(SRTServletResponse.java:1328)

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:164)

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at javax.servlet.http.HttpServletResponseWrapper.sendError(HttpServletResponseWrapper.java:164)

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at org.springframework.security.web.util.OnCommittedResponseWrapper.sendError(OnCommittedResponseWrapper.java:119)

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint.commence(BasicAuthenticationEntryPoint.java:61)

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at org.springframework.security.web.authentication.DelegatingAuthenticationEntryPoint.commence(DelegatingAuthenticationEntryPoint.java:95)

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at org.springframework.security.web.access.ExceptionTranslationFilter.sendStartAuthentication(ExceptionTranslationFilter.java:213)

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at org.springframework.security.web.access.ExceptionTranslationFilter.handleSpringSecurityException(ExceptionTranslationFilter.java:185)

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:141)

<BR>&nbsp;&nbsp;&nbsp;&nbsp;
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:334)
...
...
more

同时Liberty控制台出现如下错误(滚动到rigt查看更多):

Error reported: 406

[ERROR   ] Error Page Exception:
                                                                                                               0-0

                                                                                                               Error Page Exception
                                                                                                               com.ibm.ws.webcontainer.webapp.WebAppErrorReport: SRVE0295E

我的Liberty的server.xml如下:

<?xml version="1.0" encoding="UTF-8"?>
<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>webProfile-8.0</feature>
        <feature>springBoot-2.0</feature>
        <feature>servlet-4.0</feature>
    </featureManager>

    <basicRegistry/>

    <!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
    <httpEndpoint id="defaultHttpEndpoint"
                  httpPort="9090"
                  httpsPort="9443" />

    <!-- Automatically expand WAR files and EAR files -->
    <applicationManager autoExpand="true"/>

</server>

我的应用程序使用 Java 8、带有 Spring Integration、Spring Security、Spring REST Docs、Springfox 3.0.0-SNAPSHOT 和 Log4j 2 的 Spring Boot (2.1.3)。

请有人帮忙指出 Liberty 无法显示 Swagger 响应或提供“试用”功能的根本原因吗?就像我说的,在 Tomcat 9 上同样可以顺利运行。

真诚地, 巴拉特

【问题讨论】:

    标签: spring-boot swagger swagger-ui websphere-liberty springfox


    【解决方案1】:

    此问题可能是由于在 Liberty 19.0.0.1 上部署了 SpringBoot 2.1.3 应用程序,该应用程序支持 SpringBoot 1.5 和 2.0 应用程序,但缺少thin embedded server dependencies from Spring Boot 2.1 应用程序的能力。此后,此功能已添加到 Liberty 19.0.0.2。请更新到 Liberty 19.0.0.2 并重试您的方案。如果更新不能解决问题,我已经打开open-liberty issue 6870 进行进一步讨论和发现。

    【讨论】:

    • 我的公司不允许升级到 Liberty 19.0.0.2。所以我在 Liberty 19.0.0.1 上降级到 Spring Boot 2.0(这对我的项目有好处)为我工作!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-15
    • 2014-10-20
    • 2021-08-13
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    相关资源
    最近更新 更多