Gan*_*esh 6 java documentation spring swagger springfox
我正在非春季启动应用程序中配置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>
Run Code Online (Sandbox Code Playgroud)
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;
}
}
Run Code Online (Sandbox Code Playgroud)
添加了以下映射:
<mvc:resources mapping="swagger-ui.html" location="classpath:/META- INF/resources/"/>
<mvc:resources mapping="/webjars/**" location="classpath:/META- INF/resources/webjars/"/>
Run Code Online (Sandbox Code Playgroud)我可以访问以下网址
/v2/api-docs
/swagger-resources
Run Code Online (Sandbox Code Playgroud)
但是在加载swagger-ui.html UI时会加载,并且在服务器上会出现以下错误
No mapping found for /context/swagger-resources/configuration/ui in Dispatcher servlet
Run Code Online (Sandbox Code Playgroud)
有人可以帮忙吗?
我在我的 pom.xml 中使用 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/*.*")
);
}
}
Run Code Online (Sandbox Code Playgroud)
没有适合我的配置或资源。
当我点击 URL 时,页面就会立即出现http://localhost:8080/foobar/swagger-ui.html
归档时间: |
|
查看次数: |
11370 次 |
最近记录: |