首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Springfox Swagger2与Springfox 404错误

Springfox Swagger2与Springfox 404错误
EN

Stack Overflow用户
提问于 2017-12-15 20:15:39
回答 1查看 1.3K关注 0票数 0

我试图将Springfox Swagger2集成到现有的Spring4MVC应用程序中,并在呈现部分页面时遇到问题。

以下页面返回404错误:

  • https://localhost:9002/swagger-ui.html
  • 网络研讨会下的任何内容

以下页面工作正常,并返回JSON:

  • https://localhost:9002/swagger-resources/configuration/security
  • https://localhost:9002/swagger-resources/configuration/ui
  • https://localhost:9002/v2/api-docs

我在MVC配置中添加了以下内容:

代码语言:javascript
复制
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/"/>

https://localhost:9002/swagger-ui.html显示了一个404错误:

代码语言:javascript
复制
[15/Dec/2017:16:36:07 -0500] "GET /swagger-ui.html HTTP/1.1" 404 36691 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"

https://localhost:9002/webjars/springfox-swagger-ui/springfox.js展示了同样的情况:

代码语言:javascript
复制
[15/Dec/2017:15:10:08 -0500] "GET /webjars/springfox-swagger-ui/springfox.js HTTP/1.1" 404 36691 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.91 Safari/537.36"

web.xml

代码语言:javascript
复制
<?xml version="1.0" encoding="iso-8859-1"?>
<web-app version="2.5"
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

    <display-name>storefront</display-name>

    <!--
     We have to explicitly clear the welcome file list.
     We don't need to serve a default or index page as we can handle all the requests via spring MVC.
    -->
    <welcome-file-list>
        <welcome-file/>
    </welcome-file-list>

<context-param>
    <description>
    Spring Expression Language Support
    </description>
    <param-name>
    springJspExpressionSupport
    </param-name>
    <param-value>
    false
    </param-value>
</context-param>

    <!-- filters -->
<filter>
        <filter-name>UrlRewriteFilter</filter-name>
        <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
        <!-- set the amount of seconds the conf file will be checked for reload
        can be a valid integer (0 denotes check every time,
        -1 denotes no reload check, default -1) -->
        <init-param>
            <param-name>confReloadCheckInterval</param-name>
            <param-value>600</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>UrlRewriteFilter</filter-name>
        <url-pattern>/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>



    <filter>
    <filter-name>characterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>characterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <description>
            ResourceFilter
            Filter used to server file resources by bypassing the other filters.
        </description>
        <filter-name>resourceFilter</filter-name>
        <filter-class>com.company.storefront.servlets.ResourceFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>resourceFilter</filter-name>
        <url-pattern>/_ui/*</url-pattern>
        <url-pattern>/_public/*</url-pattern>
    </filter-mapping>

    <filter>
        <description>
            SSLTerminationFilter
            Allows for SSL termination at the loadbalancer/HTTP server level
        </description>
        <filter-name>SSLTerminationFilter</filter-name>
        <filter-class>com.acquitygroup.security.SSLTerminationFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>SSLTerminationFilter</filter-name>
        <servlet-name>DispatcherServlet</servlet-name>
        <dispatcher>REQUEST</dispatcher> 
    </filter-mapping>


    <!--  Begin custom security filters --> 

    <!--  Commented out for fixing log out issue

    <filter>
        <description>
            SecureSessionFilter
            Helps prevent session hi-jacking/fixation vulnerabilities
        </description>
        <filter-name>SecureSessionFilter</filter-name>
        <filter-class>com.acquitygroup.security.SecureSessionFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>SecureSessionFilter</filter-name>
        <servlet-name>DispatcherServlet</servlet-name>
    </filter-mapping>
     -->
    <filter>
       <filter-name>XSSFilter</filter-name>
       <filter-class>de.hybris.platform.servicelayer.web.XSSFilter</filter-class>
       <async-supported>true</async-supported>
    </filter>

    <filter-mapping>
       <filter-name>XSSFilter</filter-name>
       <url-pattern>/*</url-pattern>
       <dispatcher>REQUEST</dispatcher>
       <dispatcher>FORWARD</dispatcher>
    </filter-mapping>

    <filter>
        <description>
            Spring configured based chain of the spring configurable filter beans
        </description>
        <filter-name>storefrontFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>storefrontFilterChain</filter-name>
        <servlet-name>DispatcherServlet</servlet-name>
    </filter-mapping>
    <filter>
        <description>
            OpenRedirectInterruptFilter
            Helps prevent against Open Redirect vulnerabilities
        </description>
        <filter-name>OpenRedirectInterruptFilter</filter-name>
        <filter-class>com.acquitygroup.security.OpenRedirectInterruptFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>OpenRedirectInterruptFilter</filter-name>
        <servlet-name>DispatcherServlet</servlet-name>
    </filter-mapping>

    <!--  End custom security filters -->   

    <!-- spring based filter chain -->


    <filter>
        <description>
            SpringSecurityFilterChain
            Supports delegating to a chain of spring configured filters. The filter name
            must match the bean name.
        </description>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <servlet-name>DispatcherServlet</servlet-name>
    </filter-mapping>



    <!--  punchout filter for IE 8 -->
    <filter>
        <filter-name>P3PFilter</filter-name>
        <filter-class>com.company.core.filter.P3PServletFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>P3PFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping> 


    <!-- HTTP Session Listeners -->
    <listener>
        <description>
            The HybrisContextLoaderListener extends the usual SpringContextLoaderListener (which loads
            the context from specified location) by adding the global application context of
            the platform as parent context. With having the global context set as parent you can access
            or override beans of the global context and get the 'tenant' scope.
        </description>
        <listener-class>de.hybris.platform.spring.HybrisContextLoaderListener</listener-class>
    </listener>

    <listener>
        <description>
            The RequestContextListener exposes the 'request' scope to the context.
            Furthermore it is needed when overriding the 'jalosession' bean for your web application.
        </description>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <listener>
        <description>
            The RequestContextListener exposes the 'request' scope to the context.
            Furthermore it is needed when overriding the 'jalosession' bean for your web application.
        </description>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <!-- config -->
      <context-param>
        <description>
            The 'contextConfigLocation' param specifies where your configuration files are located.
            The 'WEB-INF/config/web-application-config.xml' file includes several other XML config
            files to build up the configuration for the application.
        </description>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/config/web-application-config.xml</param-value>
    </context-param> 

    <!-- Servlets -->

    <!-- To Avoid server start up issues due to scope tenant  -->

       <servlet>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>      
         <init-param>    
            <param-name>contextClass</param-name>
            <param-value>de.hybris.platform.spring.ctx.TenantIgnoreXmlWebApplicationContext</param-value>
        </init-param>

         <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>WEB-INF/config/web-application-config.xml</param-value>
        </init-param>

        <load-on-startup>1</load-on-startup>
    </servlet> 
   <!--   <servlet>
        <description>
            DispatcherServlet
            Spring MVC dispatcher servlet. This is the entry point for the Spring MVC application.
        </description>
        <servlet-name>DispatcherServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <description>
                Specifies the location for Spring MVC to load an additional XML configuration file.
                Because hybris is already configured with the XML spring configuration files to load
                we must set this param value to EMPTY in order to prevent loading of the default
                /WEB-INF/applicationContext.xml file.
            </description>

            <param-name>contextConfigLocation</param-name>
            <param-value></param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet> -->

    <servlet-mapping>
        <servlet-name>DispatcherServlet</servlet-name>
        <!-- Map all requests to the DispatcherServlet -->
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <!-- Uncomment in to enable handling of 500 server errors  -->
    <error-page>
        <exception-type>java.lang.Exception</exception-type>
        <location>/WEB-INF/views/pages/error/serverError.jsp</location>
    </error-page>
    <error-page>
        <error-code>500</error-code>
        <location>/WEB-INF/views/pages/error/serverError.jsp</location>
    </error-page>

    <!-- handle csrf token errors due to session timeout! -->   
    <error-page>
        <exception-type>com.acquitygroup.security.csrf.RequestConfirmationTokenException</exception-type>
        <location>/login?timeout=true</location>
   </error-page>



    <!-- Session -->

    <session-config>
        <!-- Session timeout of 30 minutes -->
        <session-timeout>240</session-timeout>
    </session-config>


    <!-- JSP Configuration -->

    <jsp-config>
        <jsp-property-group>
            <url-pattern>*.jsp</url-pattern>
            <!-- Disable JSP scriptlets and expressions -->
            <scripting-invalid>true</scripting-invalid>
            <!-- Remove additional whitespace due to JSP directives -->
            <trim-directive-whitespaces>true</trim-directive-whitespaces>
        </jsp-property-group>
    </jsp-config>

</web-app>

只是想了解一下为什么会发生这种情况,以及如何解决这个问题。

EN

回答 1

Stack Overflow用户

发布于 2017-12-27 07:45:02

请检查aop版本,它应该是相同的版本,即4x。请参考Integrating Swagger with Spring 3.0.6.RELEASEhttps://github.com/springfox/springfox/issues/938。这些是使用swagger时经常出现的错误。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47839299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档