本文整理了Java中javax.servlet.ServletContext.addListener()
方法的一些代码示例,展示了ServletContext.addListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServletContext.addListener()
方法的具体详情如下:
包路径:javax.servlet.ServletContext
类名称:ServletContext
方法名:addListener
[英]TODO SERVLET3 - Add comments
[中]TODO SERVLET3-添加注释
代码示例来源:origin: igniterealtime/Openfire
@Override
public void addListener( Class<? extends EventListener> aClass )
{
proxy.addListener( aClass );
}
代码示例来源:origin: igniterealtime/Openfire
@Override
public void addListener( String s )
{
proxy.addListener( s );
}
代码示例来源:origin: igniterealtime/Openfire
@Override
public <T extends EventListener> void addListener( T t )
{
proxy.addListener( t );
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Register a {@link ServletContextListener} that closes the given
* application context when the servlet context is destroyed.
* @param servletContext the servlet context to listen to
* @param applicationContext the application context that is to be
* closed when {@code servletContext} is destroyed
*/
protected void registerCloseListener(ServletContext servletContext, ApplicationContext applicationContext) {
if (applicationContext instanceof ConfigurableApplicationContext) {
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) applicationContext;
ServletContextDestroyedListener listener = new ServletContextDestroyedListener(cac);
servletContext.addListener(listener);
}
}
代码示例来源:origin: org.springframework.boot/spring-boot
@Override
protected void register(String description, ServletContext servletContext) {
try {
servletContext.addListener(this.listener);
}
catch (RuntimeException ex) {
throw new IllegalStateException(
"Failed to add listener '" + this.listener + "' to servlet context",
ex);
}
}
代码示例来源:origin: org.springframework/spring-web
/**
* Register a {@link ServletContextListener} that closes the given
* application context when the servlet context is destroyed.
* @param servletContext the servlet context to listen to
* @param applicationContext the application context that is to be
* closed when {@code servletContext} is destroyed
*/
protected void registerCloseListener(ServletContext servletContext, ApplicationContext applicationContext) {
if (applicationContext instanceof ConfigurableApplicationContext) {
ConfigurableApplicationContext cac = (ConfigurableApplicationContext) applicationContext;
ServletContextDestroyedListener listener = new ServletContextDestroyedListener(cac);
servletContext.addListener(listener);
}
}
代码示例来源:origin: jersey/jersey
@Override
public void onStartup(ServletContext sc) throws ServletException {
if (sc.getInitParameter(PAR_NAME_CTX_CONFIG_LOCATION) == null) {
LOGGER.config(LocalizationMessages.REGISTERING_CTX_LOADER_LISTENER());
sc.setInitParameter(PAR_NAME_CTX_CONFIG_LOCATION, "classpath:applicationContext.xml");
sc.addListener("org.springframework.web.context.ContextLoaderListener");
sc.addListener("org.springframework.web.context.request.RequestContextListener");
} else {
LOGGER.config(LocalizationMessages.SKIPPING_CTX_LODAER_LISTENER_REGISTRATION());
}
}
}
代码示例来源:origin: aol/micro-server
public void addListeners(ServletContext webappContext) {
serverData.getRootContext()
.getBeansOfType(ServletContextListener.class)
.values()
.stream()
.peek(this::logListener)
.forEach(listener -> webappContext.addListener(listener));
listenerData.forEach(it -> webappContext.addListener(it));
serverData.getRootContext()
.getBeansOfType(ServletRequestListener.class)
.values()
.stream()
.peek(this::logListener)
.forEach(listener -> webappContext.addListener(listener));
listenerRequestData.forEach(it -> webappContext.addListener(it));
}
private void logListener(ServletContextListener listener) {
代码示例来源:origin: ninjaframework/ninja
@Override
public void onStartup(Set<Class<?>> c, ServletContext servletContext) throws ServletException {
servletContext.log("Initializing NinjaFramework in container...");
servletContext.addListener(NinjaServletListener.class);
servletContext.addFilter("NinjaServletFilter", NinjaServletFilter.class)
.addMappingForUrlPatterns(null, false, "/*");
}
代码示例来源:origin: org.springframework.boot/spring-boot
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// Logger initialization is deferred in case an ordered
// LogServletContextInitializer is being used
this.logger = LogFactory.getLog(getClass());
WebApplicationContext rootAppContext = createRootApplicationContext(
servletContext);
if (rootAppContext != null) {
servletContext.addListener(new ContextLoaderListener(rootAppContext) {
@Override
public void contextInitialized(ServletContextEvent event) {
// no-op because the application context is already initialized
}
});
}
else {
this.logger.debug("No ContextLoaderListener registered, as "
+ "createRootApplicationContext() did not "
+ "return an application context");
}
}
代码示例来源:origin: spring-projects/spring-framework
/**
* Register a {@link ContextLoaderListener} against the given servlet context. The
* {@code ContextLoaderListener} is initialized with the application context returned
* from the {@link #createRootApplicationContext()} template method.
* @param servletContext the servlet context to register the listener against
*/
protected void registerContextLoaderListener(ServletContext servletContext) {
WebApplicationContext rootAppContext = createRootApplicationContext();
if (rootAppContext != null) {
ContextLoaderListener listener = new ContextLoaderListener(rootAppContext);
listener.setContextInitializers(getRootApplicationContextInitializers());
servletContext.addListener(listener);
}
else {
logger.debug("No ContextLoaderListener registered, as " +
"createRootApplicationContext() did not return an application context");
}
}
代码示例来源:origin: wildfly/wildfly
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
super.onStartup(c, ctx);
ctx.addListener(new StartupServletContextListener());
}
}
代码示例来源:origin: ch.qos.logback/logback-classic
@Override
public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException {
if (isDisabledByConfiguration(ctx)) {
StatusViaSLF4JLoggerFactory.addInfo("Due to deployment instructions will NOT register an instance of " + LogbackServletContextListener.class
+ " to the current web-app", this);
return;
}
StatusViaSLF4JLoggerFactory.addInfo("Adding an instance of " + LogbackServletContextListener.class + " to the current web-app", this);
LogbackServletContextListener lscl = new LogbackServletContextListener();
ctx.addListener(lscl);
}
代码示例来源:origin: org.springframework/spring-web
/**
* Register a {@link ContextLoaderListener} against the given servlet context. The
* {@code ContextLoaderListener} is initialized with the application context returned
* from the {@link #createRootApplicationContext()} template method.
* @param servletContext the servlet context to register the listener against
*/
protected void registerContextLoaderListener(ServletContext servletContext) {
WebApplicationContext rootAppContext = createRootApplicationContext();
if (rootAppContext != null) {
ContextLoaderListener listener = new ContextLoaderListener(rootAppContext);
listener.setContextInitializers(getRootApplicationContextInitializers());
servletContext.addListener(listener);
}
else {
logger.debug("No ContextLoaderListener registered, as " +
"createRootApplicationContext() did not return an application context");
}
}
代码示例来源:origin: oblac/jodd
/**
* Alternative way for registering Joy listeners.
* Sometimes servlet container does not allow adding new listener
* from already added listener. This method therefore registers
* the listener <i>before</i> container actually called the
* callback methods.
*/
public static void registerInServletContext(
final ServletContext servletContext,
final Class<? extends JoyContextListener> joyContextListenerClass
) {
try {
final JoyContextListener joyContextListener =
ClassUtil.newInstance(joyContextListenerClass);
joyContextListener.createJoyAndInitServletContext(servletContext);
} catch (Exception e) {
throw new JoyException(e);
}
servletContext.addListener(joyContextListenerClass);
}
代码示例来源:origin: oblac/jodd
/**
* Configures servlet context.
*/
private void configureServletContext(final ServletContext servletContext) {
servletContext.addListener(jodd.servlet.RequestContextListener.class);
if (decoraEnabled) {
final FilterRegistration filter = servletContext.addFilter("decora", jodd.decora.DecoraServletFilter.class);
filter.addMappingForUrlPatterns(null, true, contextPath);
}
final FilterRegistration filter = servletContext.addFilter("madvoc", jodd.madvoc.MadvocServletFilter.class);
filter.addMappingForUrlPatterns(madvocDispatcherTypes, true, contextPath);
}
代码示例来源:origin: Atmosphere/atmosphere
c.addListener(new ServletRequestListener() {
@Override
public void requestDestroyed(ServletRequestEvent sre) {
boolean sessionSupport = Boolean.valueOf(s);
if (sessionSupport && c.getMajorVersion() > 2) {
c.addListener(SessionSupport.class);
c.log("AtmosphereFramework : Installed " + SessionSupport.class);
代码示例来源:origin: stackoverflow.com
public class MyWebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) {
// Create the 'root' Spring application context
AnnotationConfigWebApplicationContext rootContext =
new AnnotationConfigWebApplicationContext();
rootContext.register(WebSpringConfig.class);
// Manage the lifecycle of the root application context
container.addListener(new ContextLoaderListener(rootContext));
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext dispatcherContext =
new AnnotationConfigWebApplicationContext();
dispatcherContext.register(DispatcherConfig.class);
// Register and map the dispatcher servlet
ServletRegistration.Dynamic dispatcher =
container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void testLoadSessionEventPublisher() throws Exception {
Mockito.when(context.getResource(ArgumentMatchers.contains("${APPLICATION_CONFIG_URL}"))).thenReturn(
new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes()));
initializer.initialize(context);
ArgumentCaptor<HttpSessionEventPublisher> httpSessionEventPublisherArgumentCaptor = ArgumentCaptor.forClass(HttpSessionEventPublisher.class);
verify(servletContext, atLeastOnce()).addListener(httpSessionEventPublisherArgumentCaptor.capture());
assertNotNull(httpSessionEventPublisherArgumentCaptor.getValue());
}
代码示例来源:origin: spring-projects/spring-session
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
beforeSessionRepositoryFilter(servletContext);
if (this.configurationClasses != null) {
AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext();
rootAppContext.register(this.configurationClasses);
servletContext.addListener(new ContextLoaderListener(rootAppContext));
}
insertSessionRepositoryFilter(servletContext);
afterSessionRepositoryFilter(servletContext);
}
内容来源于网络,如有侵权,请联系作者删除!