【发布时间】:2017-06-23 10:25:08
【问题描述】:
我正在使用 Springfox Swagger。这是我访问http://localhost:8088/myContextRoot/swagger-ui.html时看到的:
即只有 HTML 文件 swagger-ui.html 加载成功,其他应该在 http://localhost:8088/myContextRoot/webjars/springfox-swagger-ui 的东西(js、css 等)返回 404。
到目前为止我已经尝试过:
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>
资源-servlet.xml
<mvc:resources mapping="swagger-ui.html" location="classpath:/META-INF/resources/" />
<mvc:resources mapping="/webjars/**" location="classpath:/META-INF/resources/webjars/" />
Java 配置
@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();
}
}
使用的版本:
compile "io.springfox:springfox-swagger2:2.6.1"
compile "io.springfox:springfox-swagger-ui:2.6.1"
【问题讨论】: