新泽西2.x的定制注塑注释NULL [英] Jersey 2.x Custom Injection annotation NULL

查看:166
本文介绍了新泽西2.x的定制注塑注释NULL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟随22.1。实现定制注塑商段落

I'm following the 22.1. Implementing Custom Injection Provider paragraph

https://jersey.java.net/documentation/latest/用户guide.html#部署

我定义我的班如下:

public class PrincipalConfig extends ResourceConfig {   

  public PrincipalConfig() {    
    packages("com.vex.klopotest.secured,com.klopotek.klas.auth.injection");         
        register(new MyBinder());
    }
}

在哪里MyBinder是:

Where MyBinder is :

Public class MyBinder extends AbstractBinder implements Factory<KasPrincipal> {


@Override
protected void configure() {

    bindFactory(this).to(MyInjectable.class).in(RequestScoped.class);                
    bind(KasPersistenceDaoInjectionResolver.class)
         .to(new TypeLiteral<InjectionResolver<KasPersistenceDaoAnnot>>(){})
         .in(Singleton.class);

    }

    @Override
    public MyInjectable provide() {
    // TODO Auto-generated method stub
        return new MyInjectable();
    }

    @Override
    public void dispose(MyInjectable instance) {
        // TODO Auto-generated method stub

    }
}

这是我简单的注解:

and this is my simple annotation:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
public @interface MyAnnot {

}

我wanto使用注释在我的资源服务:

i wanto to use the annotation in my res service:

@Path("modelORA")
public class ModelRetrieverORA {

   @Context
   SecurityContext securityContext;

    @Context
    private UriInfo uriInfo;

    @MyAnnot    
    private Myinjectable Principal;

在我的web.xml部署我州servlet容器(我错了),并通过该配置code javax.ws.rs.Application:

in my web.xml i deployed Jersey servlet container (am i wrong) and javax.ws.rs.Application by this configuration code:

<servlet>
    <servlet-name>com.my.package.injection.PrincipalConfig</servlet-name>
</servlet>

<servlet-mapping>
    <servlet-name>com.my.package.injection.PrincipalConfig</servlet-name>
    <url-pattern>/rest</url-pattern>
</servlet-mapping>

走进调试模式我看到我的调用REST服务时,提供方法不会被调用......的确总是空。

Going into debug mode i see that when invoking my rest service the provide method is never called... indeed is always null.

我在哪里错了?我米工作的一个JBoss Wildfly 9.0,并使用2.21新泽西州库

Where am i wrong? I m working on a jboss Wildfly 9.0 and using Jersey 2.21 library

推荐答案

我找到了解决办法:

1)在web.xml中添加:

1) In web.xml add:

<context-param>
    <param-name>resteasy.scan</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.providers</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>resteasy.scan.resources</param-name>
    <param-value>false</param-value>
</context-param>

这样我可以从我的扫描排除战争RestEasy的。

this way i can exclude resteasy from scanning my war.

然后使用这些部署的说明:

Then use these deployment instructions:

<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param> 
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>com.klopotek.klas.auth.injection.PrincipalConfig</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
</servlet-mapping>

这是因为previous部署方法是Servlet的规格3.0。

This is because the previous deployment method was for Servlet specs 3.0.

注射现在的作品。

这篇关于新泽西2.x的定制注塑注释NULL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆