swgger2配置了之后无法访问接口主页。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency> |
@EnableSwagger2 @Configuration public class SwaggerConfig extends WebMvcConfigurationSupport { @Bean public Docket createRestApi(PropertiesConfig propertiesConfig) { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo(propertiesConfig)) .select() .apis(RequestHandlerSelectors. basePackage("com.phicomm.mobile.hermes.hamal.controller")) .paths(propertiesConfig.isSwaggerEnabled() ? PathSelectors. any() : PathSelectors.none()) .build(); } private ApiInfo apiInfo(PropertiesConfig propertiesConfig) { return new ApiInfoBuilder() .title(propertiesConfig.getSwaggerTitle()) .termsOfServiceUrl(propertiesConfig.getSwaggerServiceUrl()) .contact( new Contact(propertiesConfig.getSwaggerContactName(), propertiesConfig.getSwaggerContactUrl(), propertiesConfig.getSwaggerContactEmail())) .version(propertiesConfig.getSwaggerVersion()) .build(); } } |
@Api(value = "TestController", description = "test the swagger API TestController") |
@ApiOperation(value = "test echo", notes = "直接返回输入参数", response = CommonResponse.class) |
@ApiParam(value = "什么参数都可以" ,required=true) |
@ApiResponses(value = {@ApiResponse(code = 405, message = "Invalid input", response = PlanSyncBean.class) }) |
http://localhost:8080/swagger-ui.html |
我把配置贴出来,你参考一下,是不是哪里不对
是否配置了扫描包路径,这个是最主要的,其他的都不重要,仔细检查这个
如果你有继承了WebMvcConfigurationSupport的配置文件,你的默认配置会失效,在POM文件里加上
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>