gpt4 book ai didi

java - Swagger-ui 不显示任何 api 详细信息

转载 作者:行者123 更新时间:2023-12-02 08:27:15 25 4
gpt4 key购买 nike

我已成功将 swagger 集成到我的项目中

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>

我现在可以点击网址 http://localhost:8080/myApp/v2/api-docs并查看返回的 json 描述我的 REST api。例如

{ ? 
"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":"/myApp",
"tags":[ ?
{ ?
"name":"staff-controller",
"description":"Staff Controller"
},
{ ?
"name":"data-controller",
"description":"Data Controller"
},
{ ?
"name":"master-controller",
"description":"Master Controller"
},
{ ?
"name":"user-manager-controller",
"description":"User Manager Controller"
},
{ ?
"name":"client-controller",
"description":"Client Controller"
},
{ ?
"name":"request-controller",
"description":"Request Controller"
}
],

然后我引入了 swagger-ui 依赖项

<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>

我创建了一个 SwaggerConfig bean

@Configuration
@EnableSwagger2
public class SwaggerConfig {

@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.any()).paths(PathSelectors.any())
.build();
}
}

和 WebMVCConfig

@EnableWebMvc
public class WebMVCConfig extends WebMvcConfigurerAdapter {

@Override
public void addResourceHandlers(final ResourceHandlerRegistry registry) {
registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
}

}

但是当我导航到 http://localhost:8080/myApp/swagger-ui.html 时我看到了 swagger header ,但没有填充任何信息。 Screenshot

还有什么需要配置的吗? Swagger-ui 是否需要指向我的项目或类似项目根目录的路径?

我的 web.xml 确实配置了安全性(尽管我尝试将其关闭但没有影响)

<servlet>
<servlet-name>myApp</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:spring/application.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>myApp</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

最佳答案

根据您的配置,swagger-ui.html 的正确网址位于 http://localhost:8080/swagger-ui.html

关于java - Swagger-ui 不显示任何 api 详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39921796/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com