Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You need to define an <code>AbstractBinder</code> and register it in your JAX-RS application. The binder specifies how the dependency injection should create your classes.</p> <pre class="lang-java prettyprint-override"><code>public class MyApplicationBinder extends AbstractBinder { @Override protected void configure() { bind(MyService.class).to(MyService.class); } } </code></pre> <p>When <code>@Inject</code> is detected on a parameter or field of type <code>MyService.class</code> it is instantiated using the class <code>MyService</code>. To use this binder, it need to be registered with the JAX-RS application. In your <code>web.xml</code>, define a JAX-RS application like this:</p> <pre class="lang-xml prettyprint-override"><code>&lt;servlet&gt; &lt;servlet-name&gt;MyApplication&lt;/servlet-name&gt; &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;javax.ws.rs.Application&lt;/param-name&gt; &lt;param-value&gt;com.mypackage.MyApplication&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;MyApplication&lt;/servlet-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; </code></pre> <p>Implement the <code>MyApplication</code> class (specified above in the <code>init-param</code>).</p> <pre class="lang-java prettyprint-override"><code>public class MyApplication extends ResourceConfig { public MyApplication() { register(new MyApplicationBinder()); packages(true, "com.mypackage.rest"); } } </code></pre> <p>The binder specifying dependency injection is registered in the constructor of the class, and we also tell the application where to find the REST resources (in your case, <code>MyResource</code>) using the <code>packages()</code> method call.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload