繁体   English   中英

如何在属性文件中提供文本以提供春季休息服务?

[英]How to provide texts to swagger in a properties file for spring restful service?

我正在以昂首阔步的方式创建我的Spring restful service文档。

示例请求处理程序方法及其下面的文档。 有用:

@ApiOperation(value = "Returns user details", notes = "Returns a complete list of users details with a date of last modification.", response = User.class)
public Response getUser(@ApiParam(name = "userName", value = "Alphanumeric login to the application", required = true) @PathParam("userName") String userName) {
...
}

但是我希望将请求处理程序方法的文本提供给属性文件中的swagger注释(这样做是为了不使用文档文本增加类大小)。
因此,我创建了一个名为“application-swagger.properties”的属性文件,并在“application.properties”(spring.profiles.active = swagger)中启用它。 当我创建如下的api文档时,不显示文本。

 application-swagger.properties:
 value=Returns user details
 notes=Returns a complete list of users details with a date of last modification.

控制器类:

@Controller
@Profile("swagger")
public class UserController{
    .
    .
    @ApiOperation(value = "${value}", notes = ${notes}", response = User.class)
    public Response getUser(@ApiParam(name = "userName", value = "Alphanumeric login to the application", required = true) @PathParam("userName") String userName) {
    ...
    }
    .
    .
}

有没有办法将文本放入属性文件中的swagger注释? 谢谢你的帮助。

回答问题一直很安静,但如果有人需要帮助,可以参考。

脚步:

  1. 创建属性文件,例如swagger.properties
  2. 输入所需的消息作为键值对,其中键将用作占位符 - 例如person.id =此人的唯一标识符
  3. 而不是注释文本插入占位符 - 例如$ {person.id}
  4. 在类级别注册配置中的属性文件 - 例如。 @PropertySource( “类路径:swagger.properties”)

使用Spring Boot 1.5和Swagger 2.8,不确定以前的版本。

参考文献摘自一篇详细的文章

您不能这样做,因为注释值需要一个常量,但在您的场景中它不是常量。 请参考annotaion java doc 中的接受值 ,表示它必须是常量。

在您的情况下,最简单/可读的方法是将所有常量移动到单独的类而不是属性文件中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM