2017-02-06 23 views
0

私はSpringfox Swaggerを使用しています。これは私がhttp://localhost:8088/myContextRoot/swagger-ui.htmlにアクセスしたときに、私が見たものである。SpringのSwagger UI:HTMLファイルのみが読み込まれますが、リソースは読み込まれません。

enter image description here

すなわち、

web.xmlの

:私がこれまで試したどのような http://localhost:8088/myContextRoot/webjars/springfox-swagger-uiリターン404

ですることになって唯一のHTMLファイルswagger-ui.html正常にロードされ、他のもの(JS、CSS、など)

<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> 

リソース-servlet.xml

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

のJava設定

01使用の

バージョン:あなたはこのクラスspringfox.documentation.swagger.web.ApiResourceControllerに見れば、あなたは彼らがそれぞれ/swagger-resources/configuration/ui/swagger-resources/configuration/securityに変更されたため、/configuration/ui/configuration/securityのようなマッピングは、(io.springfox:springfox-swagger-common:2.6.1に)もはや存在しないことを

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

答えて

2

を見つけることができます春に応じて要求マッピング

は、このJavaコンフィグを使用してみてください:

@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(); 
    } 
} 
関連する問題