use of org.springframework.web.context.ContextLoaderListener in project JessMA by ldcsaa.
the class SpringInjectFilter method init.
@Override
public void init() {
servletContext = HttpHelper.getServletContext();
springMap = new HashMap<CoupleKey<Class<?>, Method>, SpringAttr[]>();
context = WebApplicationContextUtils.getWebApplicationContext(servletContext);
if (context == null) {
listener = new ContextLoaderListener();
listener.contextInitialized(new ServletContextEvent(servletContext));
context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
}
}
use of org.springframework.web.context.ContextLoaderListener in project spring-boot by spring-projects.
the class SpringBootServletInitializer method onStartup.
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
// Logger initialization is deferred in case a 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");
}
}
use of org.springframework.web.context.ContextLoaderListener in project spring-framework by spring-projects.
the class Spr8510Tests method abstractRefreshableWAC_respectsProgrammaticConfigLocations.
@Test
public void abstractRefreshableWAC_respectsProgrammaticConfigLocations() {
XmlWebApplicationContext ctx = new XmlWebApplicationContext();
ctx.setConfigLocation("programmatic.xml");
ContextLoaderListener cll = new ContextLoaderListener(ctx);
MockServletContext sc = new MockServletContext();
try {
cll.contextInitialized(new ServletContextEvent(sc));
fail("expected exception");
} catch (Throwable t) {
// assert that an attempt was made to load the correct XML
assertTrue(t.getMessage(), t.getMessage().endsWith("Could not open ServletContext resource [/programmatic.xml]"));
}
}
use of org.springframework.web.context.ContextLoaderListener in project spring-security by spring-projects.
the class AbstractSecurityWebApplicationInitializer method onStartup.
/*
* (non-Javadoc)
*
* @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.
* ServletContext)
*/
public final void onStartup(ServletContext servletContext) throws ServletException {
beforeSpringSecurityFilterChain(servletContext);
if (this.configurationClasses != null) {
AnnotationConfigWebApplicationContext rootAppContext = new AnnotationConfigWebApplicationContext();
rootAppContext.register(this.configurationClasses);
servletContext.addListener(new ContextLoaderListener(rootAppContext));
}
if (enableHttpSessionEventPublisher()) {
servletContext.addListener("org.springframework.security.web.session.HttpSessionEventPublisher");
}
servletContext.setSessionTrackingModes(getSessionTrackingModes());
insertSpringSecurityFilterChain(servletContext);
afterSpringSecurityFilterChain(servletContext);
}
use of org.springframework.web.context.ContextLoaderListener in project spring-framework by spring-projects.
the class Spr8510Tests method abstractRefreshableWAC_fallsBackToConventionBasedNaming.
/**
* If context config locations have been specified neither against the application
* context nor the context loader listener, then fall back to default values.
*/
@Test
public void abstractRefreshableWAC_fallsBackToConventionBasedNaming() {
XmlWebApplicationContext ctx = new XmlWebApplicationContext();
//ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically
ContextLoaderListener cll = new ContextLoaderListener(ctx);
MockServletContext sc = new MockServletContext();
try {
cll.contextInitialized(new ServletContextEvent(sc));
fail("expected exception");
} catch (Throwable t) {
// assert that an attempt was made to load the correct XML
System.out.println(t.getMessage());
assertTrue(t.getMessage().endsWith("Could not open ServletContext resource [/WEB-INF/applicationContext.xml]"));
}
}
Aggregations