Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.tectonica.guice;
 
Servlet-listener for intercepting REST requests and pass them through Guice before they are actually served by Jersey. This allows you to inject instances into your JAX-RS annotated classes. This class can be used along with GuiceJsfInjector to also support injection into JSF ManagedBeans.

To use it, first make sure to include the following dependency in your pom.xml:

 <dependency>
    <groupId>com.sun.jersey.contribs</groupId>
    <artifactId>jersey-guice</artifactId>
 </dependency>
 
Then, you need to extend this class and provide a constructor that would offer your own subclass of com.tectonica.jee5.GuiceRestModule, reflecting your configuration. At the minimum, this subclass needs to implement com.tectonica.jee5.GuiceRestModule.getRootPackage() or com.tectonica.jee5.GuiceRestModule.bindJaxrsResources(). For example:
 public class RestConfig extends GuiceListener
 {
  public RestConfig()
    {
       super(new GuiceRestModule()
       {
          @Override
          protected String getServingUrl()
          {
             return ...;
          }
 
          @Override
          protected String getRootPackage()
          {
             return ...;
          }
       });
    }
 }
 
Once implemented, register your listener with web.xml:
 <listener>
    <listener-class>com.example.api.RestConfig</listener-class>
 </listener>
 

Author(s):
Zach Melamed
	protected final AbstractModule module;
	protected static Injector injector;
	protected GuiceListener(AbstractModule customModule)
	{
		 = customModule;
	}
	protected Injector getInjector()
	{
		return ;
	}

given a class, generates an injected instance. Useful when an API call is needed internally.
	public static <T> T getInstance(Class<T> type)
	{
		return .getInstance(type);
	}

given an injectable instance, injects its dependencies
	public static void injectMembers(Object instance)
	{
	}
New to GrepCode? Check out our FAQ X