@Singleton public class GuiceContainer extends ServletContainer
Servlet
or Filter
for deploying root resource classes
with Guice integration.
This class must be registered using
com.google.inject.servlet.ServletModule
.
This class extends ServletContainer
and initiates the
WebApplication
with a Guice-based IoCComponentProviderFactory
,
GuiceComponentProviderFactory
, such that instances of resource and
provider classes declared and managed by Guice can be obtained.
Guice-bound classes will be automatically registered if such classes are root resource classes or provider classes. It is not necessary to provide initialization parameters for declaring classes in the web.xml unless a mixture of Guice-bound and Jersey-managed classes is required.
ServletModule
,
Serialized FormModifier and Type | Class and Description |
---|---|
class |
GuiceContainer.ServletGuiceComponentProviderFactory |
ServletContainer.ContextInjectableProvider<T>
APPLICATION_CONFIG_CLASS, FEATURE_FILTER_FORWARD_ON_404, GLASSFISH_DEFAULT_ERROR_PAGE_RESPONSE, JSP_TEMPLATES_BASE_PATH, PROPERTY_FILTER_CONTEXT_PATH, PROPERTY_WEB_PAGE_CONTENT_REGEX, RESOURCE_CONFIG_CLASS
Constructor and Description |
---|
GuiceContainer(com.google.inject.Injector injector)
Creates a new Injector.
|
Modifier and Type | Method and Description |
---|---|
protected ResourceConfig |
getDefaultResourceConfig(Map<String,Object> props,
WebConfig webConfig)
Get the default resource configuration if one is not declared in the
web.xml.
|
WebApplication |
getWebApplication() |
protected void |
initiate(ResourceConfig config,
WebApplication webapp)
Initiate the
WebApplication . |
configure, configure, configure, create, destroy, doFilter, doFilter, getDefaultResourceConfig, getServletContext, getStaticContentPattern, getWebConfig, init, init, init, load, reload, service, service
doDelete, doGet, doHead, doOptions, doPost, doPut, doTrace, getLastModified, service
@Inject public GuiceContainer(com.google.inject.Injector injector)
injector
- the Guice injectorprotected ResourceConfig getDefaultResourceConfig(Map<String,Object> props, WebConfig webConfig) throws javax.servlet.ServletException
ServletContainer
This implementation returns an instance of WebAppResourceConfig
that scans in files and directories as declared by the
ClasspathResourceConfig.PROPERTY_CLASSPATH
if present, otherwise
in the "WEB-INF/lib" and "WEB-INF/classes" directories.
An inheriting class may override this method to supply a different default resource configuration implementation.
getDefaultResourceConfig
in class ServletContainer
props
- the properties to pass to the resource configuration.webConfig
- the web configuration.javax.servlet.ServletException
- in case there was an error while retrieving the default resource configprotected void initiate(ResourceConfig config, WebApplication webapp)
ServletContainer
WebApplication
.
This method will be called once at initiation and for each reload of the Web application.
An inheriting class may override this method to initiate the Web application with different parameters.
initiate
in class ServletContainer
config
- the Resource configurationwebapp
- the Web applicationpublic WebApplication getWebApplication()
Copyright © 2013 Oracle Corporation. All rights reserved.