title: Jersey 2.26: register @Inject in ResourceConfig bindFactory cannot convert Factory to Supplier
body: <p>I'm now using Jersey and I want to Inject a <code>GeneralForm</code> map into the Resource class context, which accepts all <code>application/json</code>, <code>multipart/form-data</code> and <code>application/x-www-form-urlencoded</code> format submits.</p>
  
  <p>I follow the instructions specified under the Jersey documentation:</p>
  
  <p><a href="https://jersey.github.io/documentation/latest/ioc.html#d0e17033" rel="nofollow noreferrer">https://jersey.github.io/documentation/latest/ioc.html#d0e17033</a></p>
  
  <h3>GeneralForm.java</h3>
  
  <pre><code>package cn.easecloud.jrf.provider;
  import java.util.HashMap;
  
  public class GeneralForm extends HashMap&lt;String, Object&gt; {
  }
  </code></pre>
  
  <h3>GeneralFormFactory.java</h3>
  
  <pre><code>package cn.easecloud.jrf.provider;
  
  import org.glassfish.hk2.api.Factory;
  import javax.inject.Inject;
  import javax.servlet.http.HttpServletRequest;
  
  public class GeneralFormFactory implements Factory&lt;GeneralForm&gt; {
  
      private final HttpServletRequest request;
  
      @Inject
      public GeneralFormFactory(HttpServletRequest request) {
          this.request = request;
      }
  
      @Override
      public GeneralForm provide() {
          GeneralForm result = new GeneralForm();
          return result;
      }
  
      @Override
      public void dispose(GeneralForm t) {
      }
  
  }
  </code></pre>
  
  <p>And then I register that Factory into my ResouceConfig:</p>
  
  <pre><code>package cn.cwhale.bowei;
  
  import cn.easecloud.jrf.provider.AuthenticationFilter;
  import cn.easecloud.jrf.provider.GeneralForm;
  import cn.easecloud.jrf.provider.GeneralFormFactory;
  import org.glassfish.jersey.internal.inject.AbstractBinder;
  import org.glassfish.jersey.media.multipart.MultiPartFeature;
  import org.glassfish.jersey.process.internal.RequestScoped;
  import org.glassfish.jersey.server.ResourceConfig;
  import org.glassfish.jersey.server.spring.SpringLifecycleListener;
  import org.glassfish.jersey.server.spring.scope.RequestContextFilter;
  import org.springframework.web.filter.CommonsRequestLoggingFilter;
  
  import javax.ws.rs.ApplicationPath;
  import javax.ws.rs.container.ContainerRequestFilter;
  
  @ApplicationPath("/api/*")
  public class AppConfig extends ResourceConfig {
  
      public AppConfig() {
  
          packages("cn.cwhale.bowei");
  
          register(MultiPartFeature.class);
          register(SpringLifecycleListener.class);
          register(RequestContextFilter.class);
          register(ContainerRequestFilter.class);
          register(CommonsRequestLoggingFilter.class);
          register(AuthenticationFilter.class);
  
          register(new AbstractBinder() {
              @Override
              protected void configure() {
                  bindFactory(GeneralFormFactory.class).to(GeneralForm.class)
                  .proxy(true).proxyForSameScope(false).in(RequestScoped.class);
              }
          });
  
          property("encoding", "utf-8");
  
      }
  
  }
  </code></pre>
  
  <p>But then I failed because the <code>bindFactory</code> method accepts a <code>Supplier&lt;T&gt;</code> argument which the <code>Factory</code> class did not implemented.</p>
  
  <p><a href="https://i.stack.imgur.com/vmSnp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vmSnp.png" alt="enter image description here"></a></p>
  
  <p>And when compile:</p>
  
  <pre><code>方法 org.glassfish.jersey.internal.inject.AbstractBinder.&lt;T&gt;bindFactory(java.lang.Class&lt;? extends java.util.function.Supplier&lt;T&gt;&gt;,java.lang.Class&lt;? extends java.lang.annotation.Annotation&gt;)不适用
    (无法推断类型变量 T
      (实际参数列表和形式参数列表长度不同))
  方法 org.glassfish.jersey.internal.inject.AbstractBinder.&lt;T&gt;bindFactory(java.lang.Class&lt;? extends java.util.function.Supplier&lt;T&gt;&gt;)不适用
    (无法推断类型变量 T
      (参数不匹配; java.lang.Class&lt;cn.easecloud.jrf.provider.GeneralFormFactory&gt;无法转换为java.lang.Class&lt;? extends java.util.function.Supplier&lt;T&gt;&gt;))
  方法 org.glassfish.jersey.internal.inject.AbstractBinder.&lt;T&gt;bindFactory(java.util.function.Supplier&lt;T&gt;)不适用
    (无法推断类型变量 T
      (参数不匹配; java.lang.Class&lt;cn.easecloud.jrf.provider.GeneralFormFactory&gt;无法转换为java.util.function.Supplier&lt;T&gt;))
  </code></pre>