Java Spring Boot Swigger API不工作
这是我的Java Spring Boot Swigger API不工作,java,spring,spring-boot,spring-security,swagger,Java,Spring,Spring Boot,Spring Security,Swagger,这是我的pom.xml: <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.7.0</version> </dependency> <dependency> <groupId>io.springfo
pom.xml
:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.7.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.7.0</version>
</dependency>
这是我的WebSecurityConfig.java
:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/v2/api-docs", "/configuration/ui", "/swagger-resources", "/configuration/security", "/swagger-ui.html", "/webjars/**");
}
当我从端点执行get时http://localhost:8080/v2/api-文档
我找回了我的JSON:
{
"swagger": "2.0",
"info": {
"description": "Api Documentation",
"version": "1.0",
"title": "Api Documentation",
"termsOfService": "urn:tos",
"contact": {},
"license": {
"name": "Apache 2.0",
"url": "http://www.apache.org/licenses/LICENSE-2.0"
}
},
"host": "localhost:8080",
"basePath": "/",
//ETC
}
但是,当我尝试访问localhost:8080/swagger UI.html
上的UI时,我得到一个空白页面,如下所示:
如果我点击这个页面,我就会得到提升
我做错了什么?这是某种spring安全问题吗?您可以使用
springfox.documentation.Swagger.v2.path
属性,例如。
application.yml
中的springfox.documentation.swagger.v2.path:/rest/docs
我已经发布了一个示例。它很可能是spring安全性不允许/阻止您的端点被发现。尝试将您的ant matchers更改为以下内容,看看是否有帮助。安全/ui配置终结点不正确
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(
"/v2/api-docs",
"/swagger-resources/configuration/ui",
"/swagger-resources",
"/swagger-resources/configuration/security",
"/swagger-ui.html",
"/webjars/**");
}
将“招摇过市”版本更改为2.9.2它将正常工作
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>
伊奥·斯普林福克斯
springfox-Swagger 2
2.9.2
你能把你的代码放在某个地方吗?试着在SwaggerConfig
类中将方法名从swagger()
更改为api()
。试着使用url:,在末尾带有#符号显示你的控制器?重复:我认为这也是一个spring安全问题,但不幸的是,这不起作用。你能帮我解决这个问题吗?这并没有真正的帮助,因为我已经可以从http://localhost:8080/v2/api-文档
。我就是无法从swagger-ui.html中读取it@Richard尝试将web安全的忽略列表中的“/swagger resources”
更改为“/swagger resources/**”
,因为swagger转到/swagger resources/configuration/ui
端点以获取其配置。@Richard我已经用安全配置更新了我的github示例。
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.9.2</version>
</dependency>