Java 无法推断基本url。这在使用动态servlet注册或API位于API网关swagger 2.10.5之后时很常见
试图用spring boot Rest API配置swagger 2.10.5,但不断出现错误Java 无法推断基本url。这在使用动态servlet注册或API位于API网关swagger 2.10.5之后时很常见,java,spring,spring-boot,swagger,springfox,Java,Spring,Spring Boot,Swagger,Springfox,试图用spring boot Rest API配置swagger 2.10.5,但不断出现错误无法推断基本url。这在使用动态servlet注册或API位于API网关后面时很常见 格拉德尔 compile "io.springfox:springfox-swagger2:2.10.5" compile "io.springfox:springfox-swagger-ui:2.10.5" plugins { id 'org.springframew
无法推断基本url。这在使用动态servlet注册或API位于API网关后面时很常见
格拉德尔
compile "io.springfox:springfox-swagger2:2.10.5"
compile "io.springfox:springfox-swagger-ui:2.10.5"
plugins {
id 'org.springframework.boot' version '2.3.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
配置文件
@Configuration
@ComponentScan
@EnableSwagger2WebMvc
@ComponentScan(basePackageClasses = {
Test.class
})
public class SpringFoxConfig {
@Bean
public Docket apiDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
@SpringBootApplication
public class MeroRentalRestApiApplication {
public static void main(String[] args) {
SpringApplication.run(MeroRentalRestApiApplication.class, args);
}
}
应用程序文件
@Configuration
@ComponentScan
@EnableSwagger2WebMvc
@ComponentScan(basePackageClasses = {
Test.class
})
public class SpringFoxConfig {
@Bean
public Docket apiDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
}
@SpringBootApplication
public class MeroRentalRestApiApplication {
public static void main(String[] args) {
SpringApplication.run(MeroRentalRestApiApplication.class, args);
}
}
SpringFoxConfig和应用程序在同一个包中
尝试了许多来自世界各地的解决方案
如果有人在使用2.10.5,并且面临相同的问题,那么在我的情况下,我可以通过添加以下依赖项来解决它:springfox spring webmvc具有相同的版本(2.10.5)。我的pom.xml文件中已经有springfox-swagger 2和springfox-swagger ui依赖项
我从中得到了线索,可能尝试使用注解
@EnableSwagger2
?或者您可以将依赖项更改为新的swaggerorg.springdoc:springdoc openapi ui
@VasylSarzhynskyi我无法将EnableSwagger 2用于版本swagger 2.10.5。它不包含。这解决了我的问题