简体   繁体   English

如何从属性文件初始化Jersey查询参数的默认值

[英]How to initialized the default value of a Jersey query parameter from properties file

I'm working on a Jersey/Guice project. 我正在进行Jersey / Guice项目。

I have a query parameter defined on class level. 我在类级别定义了一个查询参数。 I used the @DefaultValue annotation till now. 到目前为止,我一直使用@DefaultValue注释。 But Now I have to take the default value from a properties file. 但是现在我必须从属性文件中获取默认值。 As the value passed to the annotation has to be a constant I can not take it form the property file. 由于传递给注释的值必须是一个常量,因此我无法将其从属性文件中提取出来。

Does anyone knows a Jersey/Guice mechanism to accomplish this task? 有谁知道Jersey / Guice机制来完成此任务?

您可以定义一个使用属性名称的自定义注释,然后为该注释编写一个InjectionResolver,如果未填充该查询参数,它将从属性文件中读取值

There isn't really a simple solution to this (ie adding another annotation and being done with it). 确实没有一个简单的解决方案(即添加另一个注释并使用它完成)。 But you could define a custom BeanParam and replace the injected QueryParam s with their appropriate property values there. 但是,您可以定义一个自定义BeanParam然后在其中将注入的QueryParam替换为其相应的属性值。

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

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