是否有一种不使用@Value注释就可以在春季从外部属性文件中读取文本的方法。例: application.properties
var.foo="hello"我可以将它注入spring中
@Value("${var.foo}") String value;作为类变量。是否有一种不使用@Value注释来包含此属性的方法。类似于JSR验证的方式。
@NotNull(message={custom.notnull})并在ValidationMessages.properties文件中将此属性值外部化。
例如,如果我有一个资源(web组件)类,如果我必须使用Swagger注释来记录它们,
@controller
@path("/")
@Api(description = "User Resource API")
public class UserResource {
@Path("/users")
@GET
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(value = "returns user details", notes = "some notes")
public User getUser() {
return new User(123, "Joe", "Montana");
}
}而模特,
@ApiModel("user model")
public class User {
@ApiModelProperty(value = "This represents user id")
private String id;
private String firstName;
private String lastName;
...
}如何将此字符串/句子/消息外部化为外部属性文件。我认为这适用于一般的Java注释和spring,而不是特定于Swagger。我指定Swagger的原因是,如果就像hibernate验证一样,Java库可以选择在外部ValidationMessages.properties文件中指定这些消息,而spring默认知道可以(或者可以配置)获取这些消息。
Swagger提供了这样的选择吗?如果没有,我如何设置一个?
根本的问题是,我不想让我的代码/逻辑与文档相关的数据(元数据)混淆。
发布于 2016-09-01 10:25:30
如果您正在使用Spring,则可以尝试此方法,而无需进行任何特殊的配置。
@environment.getProperty('property')https://stackoverflow.com/questions/39107413
复制相似问题