【问题标题】:Jersey 2 filter value for field with Spring framework使用 Spring 框架的 Jersey 2 过滤器值
【发布时间】:2018-02-13 20:39:09
【问题描述】:

我需要知道是否可以使用 spring 的 @Value 机制将值填充到 Jersey 2 过滤器(@Provider)中

@Provider
public class AppConfigFilter implements ContainerRequestFilter {
    @Value("${some.prop.key}")
    private String aValue;
    // class implementation
}

【问题讨论】:

  • 您是否通过添加 @Component 使其成为 Spring bean?
  • 感谢@PaulSamsotha,刚刚成功。

标签: java spring filter properties jersey-2.0


【解决方案1】:

假设设置正确(spring、jersey 2 等),添加 @Component 可以工作并且不会产生冲突/重复实例化。

@Provider
@Component
public class AppConfigFilter implements ContainerRequestFilter {
    @Value("${some.prop.key}")
    private String aValue;
    // class implementation
}

【讨论】:

    猜你喜欢
    • 2017-11-08
    • 2013-03-12
    • 2015-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多