JAX-WS Guice integration

Google Guice - light weight dependecy injection framework.

How to Install

Download the extension (links below) and put it on the classpath of your web services project. You also need jax-ws and guice. In the pom, the dependecies are jax-ws 2.1.3 and guice 1.0, but i've run it against later versions without problems.
  • Download the jar (look below)
  • Put it on the classpath
  • Annotate your web service with @GuiceManaged(module = { YourModule.class, ...}) (check below for example)
  • Inject dependecies like crazy


The only thing you need to change in your current web service end points is to annotate them with @GuiceManaged like below. For guice details, please check the guice documentation
@GuiceManaged(module = WebServiceModule.class)
public class AddNumbersImpl implements AddNumbers {

    private Calculator calculator;

    public void setCalculator(Calculator calc)
    public int addNumbers(int num1, int num2)
        return this.calculator.calc(num1,num2);
The WebServiceModule looks like this:
public class WebServiceModule extends AbstractModule {
    protected void configure() {
This means that Guice will find all @Inject annotations and then inject a singleton instance of CalculatorImpl.class wherever it finds Calculator.class.

Guice scopes

It is possible to have both Singleton and the default "request"-scope. I.e. if you define your Endpoint implementation in Singleton scope, Guice will only create one instance of it, and if you don't define any scope at all, guice will create a new instance of the endpoint class for every web service request. Note that since the endpoint implementation class is not injected anywhere, you need to either annotate the class with @Singleton, or do like this:
in your module.


Binaries are deployed to maven, to use it, add this to your pom.xml:

And also this repository since jax-ws commons stuff are not synced to the central maven repository:
      <name>Java.net Repository for Maven</name>


Version ChangesAdded
0.1DownloadInitial rev.2008-11-05
0.2DownloadUpdated - allow several Modules in GuiceManaged annotation using the { Module1.class , ..} syntax. Let module instantiation errors propagate to framework2008-11-28
0.3DownloadMaven support2008-12-14
0.4DownloadSupport for @Resource and getting WebServiceContext using @Inject2008-12-25
0.5DownloadFixes, support singletons cross several web service endpoints, integrate with guiceyfruit for JSR250 compatibility (Patch sent in by Ronak Patel)2009-08-29


Sources are stored in Subversion. Read more
Terms of Use; Privacy Policy; Copyright ©2013-2017 (revision 20160708.bf2ac18)
Please Confirm