Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to set an AbstractBinder in Jersey
    text
    copied!<p>I'm trying to implement my HK2 binding in Jersey, in a servlet / tomcat context.</p> <p>I do, in a servlet which extends org.glassfish.jersey.servlet.ServletContainer :</p> <pre><code> @Override public void init(ServletConfig config) throws ServletException { super.init(config); // BinderInjection extends org.glassfish.hk2.utilities.binding.AbstractBinder getConfiguration().register(new BinderInjection()); } </code></pre> <p>... but I get :</p> <pre><code>java.lang.IllegalStateException: The resource configuration is not modifiable in this context. at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:270) at org.glassfish.jersey.server.ResourceConfig$ImmutableState.register(ResourceConfig.java:218) at org.glassfish.jersey.server.ResourceConfig.register(ResourceConfig.java:448) at A_Servlet.init(RestServlet.java:45) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1190) </code></pre> <p>So how can I do my own HK2 binding ?</p> <p><strong>Why this question ? (edit)</strong></p> <p>It's for EntityManager and JPA in Jersey.</p> <p>With Netbeans, if I generate an AbstractFacade it put </p> <pre><code> @PersistenceContext(unitName = "myunit") private EntityManager em; </code></pre> <p>... and :</p> <pre><code> @Override protected EntityManager getEntityManager() { return em; } </code></pre> <p>But, when I call the service, em is null. So I suppose it's @PersistenceContext which doesn't work ?</p> <p>If I use the solution <a href="http://scn.sap.com/people/maxim.maltsev/blog/2012/12/11/put-jpa-in-your-web-app-tomcat-eclipselink" rel="nofollow">Tutorial: Put JPA in your Web App (tomcat, EclipseLink) and provide Rest JSON output</a> all work like a charm, but I don't like use static variable <em>private static EntityManagerFactory emf;</em> for entity manager.</p> <p>Thanks.</p>
 

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