相关疑难解决方法(0)

Jersey 2.x具有属性的自定义注入注释

我正在从DropWizard 0.7.1迁移到0.8.1.这包括从Jersey 1.x迁移到2.x. 在我使用Jersey 1.18.1的实现中,我实现了MyProvider(为简单起见改变了所有类名)InjectableProvider.该类将创建MyInjectable包含自定义注入注释的对象MyToken.MyToken包含传递和读取的各种属性MyInjectable.最后,在Application类中我注册了一个新的实例MyProvider,如下所示.

我做了一些研究,似乎无法解决我在泽西岛2.x中如何重新创建(或替代,我认为)这样一个场景.

这是当前的1.18.1实现:

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ ElementType.PARAMETER, ElementType.FIELD })
    public @interface MyToken {

        // Custom annotation containing various attributes
        boolean someAttribute() default true;
        // ...
    }

    public class MyProvider implements InjectableProvider<MyToken, Parameter> {

        // io.dropwizard.auth.Authenticator
        private final Authenticator<String, MyObject> authenticator;

        public MyProvider(Authenticator<String, MyObject> authenticator) {
            this.authenticator = authenticator;
        }

        @Override
        public ComponentScope getScope() {
            return ComponentScope.PerRequest;
        }

        @Override
        public Injectable<?> getInjectable(ComponentContext …
Run Code Online (Sandbox Code Playgroud)

java jersey dropwizard jersey-2.0 hk2

11
推荐指数
1
解决办法
9706
查看次数

标签 统计

dropwizard ×1

hk2 ×1

java ×1

jersey ×1

jersey-2.0 ×1