Tag: hk2

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

我正在从DropWizard 0.7.1迁移到0.8.1。 这包括从Jersey 1.x迁移到2.x. 在我使用Jersey 1.18.1的实现中,我实现了一个实现InjectableProvider的MyProvider (为了简单起见改变了所有的类名)。 这个类将创buildMyInjectable对象,包含自定义注入注释MyToken 。 MyToken包含MyToken传递和读取的各种属性。 最后,在Application类中,我注册了一个MyProvider的新实例,如下所示。 我已经做了一些研究,似乎无法绕过我在泽西2.x上重新创build(或replace,我想是)这样一个场景。 这里是目前的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 […]

泽西岛2.0的dependency injection

从头开始,没有任何以前的泽西岛1.x的知识,我很难理解如何在我的Jersey 2.0项目中设置依赖项注入。 我也明白HK2可以在泽西岛2.0,但我似乎无法find有助于泽西岛2.0集成的文件。 @ManagedBean @Path("myresource") public class MyResource { @Inject MyService myService; /** * Method handling HTTP GET requests. The returned object will be sent * to the client as "text/plain" media type. * * @return String that will be returned as a text/plain response. */ @GET @Produces(MediaType.APPLICATION_JSON) @Path("/getit") public String getIt() { return "Got […]