title: Define bean using factory method in plain Java EE - WITHOUT Spring
body: <p>I want to create a bean which can be automatically injected (autowired) by plain Java EE, <strong>not with Spring</strong>.</p>
  
  <p>The code I have is this:</p>
  
  <pre><code>import javax.ws.rs.client.Client;
  import javax.ws.rs.client.ClientBuilder;
  
  @ApplicationScoped
  public class MyConnector {
      ....
      private Client client = ClientBuilder.newClient();
      ....
  }
  </code></pre>
  
  <p>I'd like to use dependency injection like that instead:</p>
  
  <pre><code>    @Inject
      private Client client;
  </code></pre>
  
  <p>In good old Spring I would just define the bean following the guideline <a href="http://docs.spring.io/spring/docs/3.1.0.M1/spring-framework-reference/html/beans.html#beans-factory-class-static-factory-method" rel="nofollow">http://docs.spring.io/spring/docs/3.1.0.M1/spring-framework-reference/html/beans.html#beans-factory-class-static-factory-method</a></p>
  
  <pre><code>&lt;bean id="client"
      class="javax.ws.rs.client.ClientBuilder"
      factory-method="createInstance"/&gt;
  </code></pre>
  
  <p>and the <code>@Autowired</code> would inject the proper bean.</p>
  
  <p><strong>QUESTION</strong>: Can I achieve the same somehow in the <strong>plain Java EE</strong> without Spring? Can I define a bean in a similar way - and if so, where (in which configuration file)?</p>