We are using GUICE framework as part of service layer. Now there is a requirement on to build JAX-WS Web services. We have built the web services using JDK 1.6 JAX-WS API. But now, we are not able to use any of the GUICE resources as we Web Service is not guice managed.
We are using Guice 3.0. How do we achieve this?
Tried the following link
http://jax-ws-commons.java.net/guice/, but did not work out and finally got to know that this is compatible only with Guice 2.0 in some forum.
One more approach tried was
http://developian.blogspot.in/2008/11/google-guice-and-jax-ws.html,
But this internally will start using some of the sun API which are access restricted and hence I dont want to use…
Now what is the best approach or alternative any any other solution.
Please advice.
Thanks
Well, you could inject an EJB that holds the guice injector. This means, you may use an EJB in case you use Java EE. That EJB should be a Singleton an handles only the holding the injector. In case you want to inject something this is the bean you get the injector from. Of course you must create the injector when calling it the first time via Guice.createInjector(). When having the injector it is no problem injecting other classes with the method getInstance(Class clazz) of the injector. You must access the injector only in your webservice the first time you call a class that uses injection.
Otherwise you could use a static injector within the webservice. Maybe that would be not as clean but it would work. This requires you to create the injector within the constructor. E.g. in an abstract service class all webservices depend on. Then you are able to access the injector in the service an do the same as described above.