OpenApi在服务器启动时添加服务器
我尝试在Swagger UI上修改服务器列表(或默认服务器)。 1/在春季(不是春季启动)配置类我添加以下内容:
@Bean
public OpenAPI customOpenAPI() {
log.info("<<<customOpenAPI>>>");
Server server = new Server();
server.setUrl("http://localhost:8091/eatery_spring_rs/rs/");
return new OpenAPI()
.servers(List.of(server));
}
2/,但我从未在Swagger UI上获得结果,没有添加服务器:
3/ maven依赖关系是:
<!--SWAGGER-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.7</version>
</dependency>
<!-- END -->
5/ Question: 是否可以按程序更改上下文路径或添加服务器URL?
I try to modify server list (or default server) on Swagger UI.
1/ On Spring (Not Spring Boot) configuration class I add this :
@Bean
public OpenAPI customOpenAPI() {
log.info("<<<customOpenAPI>>>");
Server server = new Server();
server.setUrl("http://localhost:8091/eatery_spring_rs/rs/");
return new OpenAPI()
.servers(List.of(server));
}
2/ But I never obtain result on Swagger UI, no server is added :
3/ Maven dependencies are :
<!--SWAGGER-->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>3.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-ui -->
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.6.7</version>
</dependency>
<!-- END -->
5/ Question :
Is it possible to change context path, or add server URL, by program ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
6/我可以贴上问题的描述
应用程序的上下路路径还不完整
这是一个Spring 5.3应用程序,从应用程序服务器中的 web.xml 开始。
像tomcat,...
这是web.xml定义:
`
这意味着真实上下文路径是:[app.context] /rs ,但在以下情况下:
@Bean Public DiCket API(ServletContext ServletContext){
servletContext等于 [app.context] not to [app.context]/rs
它的帮助 ?
6/ I can affine the description of problem
The context path of application is not complete
It is a Spring 5.3 application, start with web.xml in App Server.
like Tomcat, ...
This is the web.xml definition :
`
This mean that the real context path is : [app.context]/rs but in the case of :
@Bean public Docket api(ServletContext servletContext) {
servletContext is equal to [app.context] NOT to [app.context]/rs
It's help ?