我试图在非春季启动应用程序中配置swagger ui.我做了以下事情.
1.添加了以下依赖项
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>org.webjars</groupId>
<artifactId>bootstrap</artifactId>
<version>3.3.5</version>
</dependency>
2.添加了Swagger Config类
@Configuration
@EnableSwagger2
@EnableWebMvc
//@PropertySource("classpath:/swagger.properties")
public class SwaggerConfig {
@Bean
public Docket proposalApis(){
return new Docket(DocumentationType.SWAGGER_2)
.groupName("test")
.select()
.apis(RequestHandlerSelectors.basePackage("com.test.abc"))
.paths(PathSelectors.regex("/test1.*"))
.build()
.apiInfo(testApiInfo());
}
private ApiInfo testApiInfo() {
ApiInfo apiInfo = new ApiInfoBuilder().title("Test APIs").description("GET POST PUT methods are supported ").version("V1").build();
return apiInfo;
}
}
>添加了以下映射:
<mvc:resources mapping="swagger-ui.html" location="classpath:/META- INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META- INF/resources/webjars/"/>
我可以访问以下网址
/v2/api-docs
/swagger-resources
但是加载swagger-ui.html UI时会加载并在服务器上获得跟随错误
No mapping found for /context/swagger-resources/configuration/ui in Dispatcher servlet
有人可以帮忙吗?
解决方法:
我在我的pom中使用Swagger版本2.3.1.我想知道为什么你有springfox-swagger2和springfox-swagger-ui文件的不同版本?
我的SwaggerConfig类看起来像这样.没有属性:
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Autowired
private TypeResolver typeResolver;
@Bean
public Docket swaggerSpringMvcPlugin() {
return new Docket(DocumentationType.SWAGGER_2)
.groupName("FooBar")
.select()
//Ignores controllers annotated with @CustomIgnore
.apis(any()) //Selection by RequestHandler
.paths(paths()) // and by paths
.build()
.apiInfo(apiInfo()
);
}
private ApiInfo apiInfo() {
return new ApiInfo("FooBar",
"A java server based on SpringBoot",
"1.0.0",
null,
"author","","");
}
//Here is an example where we select any api that matches one of these paths
private Predicate<String> paths() {
return or(
regex("/foobar/*.*")
);
}
}
没有任何配置或资源.
当我点击URL http:// localhost:8080 / foobar / swagger-ui.html时,页面会出现