Spring Can';不读招摇过市的JSON
我已经按照下面的链接使用Swagger with Spring为我的REST服务创建了API文档Spring Can';不读招摇过市的JSON,spring,rest,swagger,swagger-ui,Spring,Rest,Swagger,Swagger Ui,我已经按照下面的链接使用Swagger with Spring为我的REST服务创建了API文档 一切都进行得很顺利,但当我尝试使用url访问用于swagger的api文档时,我发现无法读取swagger JSON。有人能帮忙吗?大摇大摆不要在本地工作! 您可以通过这种方式下载本地文件 @Configuration @EnableSwagger // Loads the spring beans required by the framework public class MySwaggerC
一切都进行得很顺利,但当我尝试使用url访问用于swagger的api文档时,我发现无法读取swagger JSON。有人能帮忙吗?大摇大摆不要在本地工作! 您可以通过这种方式下载本地文件
@Configuration
@EnableSwagger
// Loads the spring beans required by the framework
public class MySwaggerConfig
{
private SpringSwaggerConfig springSwaggerConfig;
/**
* Required to autowire SpringSwaggerConfig
*/
@Autowired
public void setSpringSwaggerConfig(SpringSwaggerConfig springSwaggerConfig)
{
this.springSwaggerConfig = springSwaggerConfig;
}
/**
* Every SwaggerSpringMvcPlugin bean is picked up by the swagger-mvc
* framework - allowing for multiple swagger groups i.e. same code base
* multiple swagger resource listings.
*/
@Bean
public SwaggerSpringMvcPlugin customImplementation()
{
return new SwaggerSpringMvcPlugin(this.springSwaggerConfig).apiInfo(apiInfo()).includePatterns(
".*?");
}
private ApiInfo apiInfo()
{
ApiInfo apiInfo = new ApiInfo(
"xx",
"xxxx",
"My Apps API terms of service",
"xxx",
null,
null);
return apiInfo;
}
}
<dependency>
<groupId>com.mangofactory</groupId>
<artifactId>swagger-springmvc</artifactId>
<version>0.9.5</version>
</dependency>
@配置
@使能招摇
//加载框架所需的Springbean
公共类MySwaggerConfig
{
私有SpringSwiggerConfig SpringSwiggerConfig;
/**
*需要自动连接SpringSwagger配置
*/
@自动连线
public void setSpringSwaggerConfig(SpringSwaggerConfig SpringSwaggerConfig)
{
this.springSwaggerConfig=springSwaggerConfig;
}
/**
*每一个招摇过市的mvc都是招摇过市的mvc挑选出来的
*框架-允许多个招摇过市的组,即相同的代码库
*多个招摇过市的资源列表。
*/
@豆子
公共炫耀SpringMVCPlugin customImplementation()
{
返回新的SwaggerSpringMvcPlugin(this.springSwaggerConfig.apinfo(apinfo()).includePatterns(
".*?");
}
私有apinfo apinfo()
{
apinfo apinfo=新的apinfo(
“xx”,
“xxxx”,
“我的应用程序API服务条款”,
“xxx”,
无效的
无效);
返回apinfo;
}
}
芒果工厂
大摇大摆
0.9.5
我通过将下一个文件添加到资源文件夹解决了这个问题
招摇过市
添加了以下属性:
springfox.documentation.swagger.v2.path=/api/swagger.json
然后在代码中添加:
@Configuration
@EnableSwagger2
@PropertySource(value = "classpath:swagger.properties")
public class PathConfiguration {
@Value("${springfox.documentation.swagger.v2.path}")
private String swagger2Endpoint;
然后是Docket配置的简单bean,如:
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build();
}
它将使这一问题如下:
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("Swagger Group One API")
.select()
.apis(RequestHandlerSelectors.basePackage("com.xingyun"))
.paths(PathSelectors.any())
.build();
}
修正如下是好的
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.groupName("SwaggerGroupOneAPI")
.select()
.apis(RequestHandlerSelectors.basePackage("com.xingyun"))
.paths(PathSelectors.any())
.build();
}
您的
/rest/api文档
路径应该包含一个招摇过市的规范文件。当您的浏览器指向url时,如果您安装了swagger ui
,它将读取此文件并将其呈现到一个漂亮的API文档网页。您可以提供其他详细信息吗?为什么你说它在本地无法工作?如果你在“本地主机”中启动你的应用程序,你就不能使用在线版本。您需要为本地下载并运行Swigger UI。