2017-02-06 1 views
0

J'utilise Springfox Swagger. Voilà ce que je vois quand j'accéder http://localhost:8088/myContextRoot/swagger-ui.html:Swagger UI au printemps: seul le fichier HTML est chargé, mais pas les ressources

enter image description here

à savoir seul le fichier HTML swagger-ui.html est chargé avec succès, d'autres choses (js, css, etc.), qui devait être à http://localhost:8088/myContextRoot/webjars/springfox-swagger-ui retours 404.

Ce que j'ai essayé jusqu'à présent:

web.xml

<servlet-mapping> 
    <servlet-name>default</servlet-name> 
    <url-pattern>/swagger-ui.html</url-pattern> 
</servlet-mapping> 

<servlet-mapping> 
    <servlet-name>default</servlet-name> 
    <url-pattern>/webjars/**</url-pattern> 
</servlet-mapping> 

ressources servlet.xml

<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" /> 
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/" /> 

Java config

@Configuration 
@EnableWebSecurity 
@EnableWebMvcSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 
     @Override 
     protected void configure(HttpSecurity http) throws Exception { 
       http 
       .authorizeRequests() 
       .antMatchers("/v2/api-docs", "/configuration/ui/**", "/swagger-resources", "/configuration/security/**", 
         "/webjars/**", "/swagger-ui.html") 
       .permitAll(); 
     } 
    } 

Versions utilisées:

compile "io.springfox:springfox-swagger2:2.6.1" 
compile "io.springfox:springfox-swagger-ui:2.6.1" 

Répondre

2

Si vous regardez dans cette classe springfox.documentation.swagger.web.ApiResourceController, vous pouvez constater que les correspondances comme /configuration/ui et /configuration/security n'existent plus (en io.springfox:springfox-swagger-common:2.6.1), parce qu'ils ont été changés /swagger-resources/configuration/ui et /swagger-resources/configuration/security respectivement selon Spring Mapping demande

Essayez d'utiliser cette Java Config:

@Configuration 
@EnableWebSecurity 
@EnableWebMvcSecurity 
public class SecurityConfig extends WebSecurityConfigurerAdapter { 
    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .authorizeRequests() 
      .antMatchers("/v2/api-docs", "/swagger-resources/**", "/webjars/**", "/swagger-ui.html") 
      .permitAll(); 
    } 
}