Spring中的招摇过市UI:只加载HTML文件,但不加载资源

Spring中的招摇过市UI:只加载HTML文件,但不加载资源,spring,swagger,springfox,Spring,Swagger,Springfox,我在用Springfox招摇过市。这是我访问时看到的: 也就是说,只有HTML文件swagger ui.HTML加载成功,其他文件(js、css等)返回404 到目前为止,我所尝试的: web.xml <servlet-mapping> <servlet-name>default</servlet-name> <url-pattern>/swagger-ui.html</url-pattern> </servle

我在用Springfox招摇过市。这是我访问时看到的:

也就是说,只有HTML文件
swagger ui.HTML
加载成功,其他文件(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>
使用的版本:

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

如果查看此类
springfox.documentation.swagger.web.ApiResourceController
,您会发现像
/configuration/ui
/configuration/security
这样的映射不再存在(在
io.springfox:springfox-swagger-common:2.6.1
),因为它们分别在
/swagger resources/configuration/ui
/swagger resources/configuration/security
上根据Spring请求映射进行了更改

尝试使用以下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();
    }
}

如果查看此类
springfox.documentation.swagger.web.ApiResourceController
,您会发现像
/configuration/ui
/configuration/security
这样的映射不再存在(在
io.springfox:springfox-swagger-common:2.6.1
),因为它们分别在
/swagger resources/configuration/ui
/swagger resources/configuration/security
上根据Spring请求映射进行了更改

尝试使用以下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();
    }
}

我从
2.7.0
升级到
2.8.0
时遇到了这个问题


我只需清理
Chrome Web浏览器
cookie和会话就可以解决这个问题。

我在升级
springfox-swagger2
2.7.0
2.8.0
时遇到了这个问题

我通过清理
chromewebbrowser
cookie和会话来修复它

@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();
    }
}