本文整理汇总了Java中org.springframework.web.context.ContextLoaderListener.contextInitialized方法的典型用法代码示例。如果您正苦于以下问题:Java ContextLoaderListener.contextInitialized方法的具体用法?Java ContextLoaderListener.contextInitialized怎么用?Java ContextLoaderListener.contextInitialized使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.ContextLoaderListener
的用法示例。
在下文中一共展示了ContextLoaderListener.contextInitialized方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: abstractRefreshableWAC_respectsProgrammaticConfigLocations
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
@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]"));
}
}
示例2: abstractRefreshableWAC_respectsInitParam_overProgrammaticConfigLocations
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
/**
* If a contextConfigLocation init-param has been specified for the ContextLoaderListener,
* then it should take precedence. This is generally not a recommended practice, but
* when it does happen, the init-param should be considered more specific than the
* programmatic configuration, given that it still quite possibly externalized in
* hybrid web.xml + WebApplicationInitializer cases.
*/
@Test
public void abstractRefreshableWAC_respectsInitParam_overProgrammaticConfigLocations() {
XmlWebApplicationContext ctx = new XmlWebApplicationContext();
ctx.setConfigLocation("programmatic.xml");
ContextLoaderListener cll = new ContextLoaderListener(ctx);
MockServletContext sc = new MockServletContext();
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");
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 [/from-init-param.xml]"));
}
}
示例3: abstractRefreshableWAC_fallsBackToInitParam
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
/**
* If setConfigLocation has not been called explicitly against the application context,
* then fall back to the ContextLoaderListener init-param if present.
*/
@Test
public void abstractRefreshableWAC_fallsBackToInitParam() {
XmlWebApplicationContext ctx = new XmlWebApplicationContext();
//ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically
ContextLoaderListener cll = new ContextLoaderListener(ctx);
MockServletContext sc = new MockServletContext();
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");
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().endsWith(
"Could not open ServletContext resource [/from-init-param.xml]"));
}
}
示例4: customAbstractRefreshableWAC_fallsBackToInitParam
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
/**
* Ensure that any custom default locations are still respected.
*/
@Test
public void customAbstractRefreshableWAC_fallsBackToInitParam() {
XmlWebApplicationContext ctx = new XmlWebApplicationContext() {
@Override
protected String[] getDefaultConfigLocations() {
return new String[] { "/WEB-INF/custom.xml" };
}
};
//ctx.setConfigLocation("programmatic.xml"); // nothing set programmatically
ContextLoaderListener cll = new ContextLoaderListener(ctx);
MockServletContext sc = new MockServletContext();
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");
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 [/from-init-param.xml]"));
}
}
示例5: abstractRefreshableWAC_fallsBackToConventionBasedNaming
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
/**
* 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();
// no init-param set
//sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM, "from-init-param.xml");
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]"));
}
}
示例6: genericWAC
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
/**
* Ensure that ContextLoaderListener and GenericWebApplicationContext interact nicely.
*/
@Test
public void genericWAC() {
GenericWebApplicationContext ctx = new GenericWebApplicationContext();
ContextLoaderListener cll = new ContextLoaderListener(ctx);
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(ctx);
scanner.scan("bogus.pkg");
cll.contextInitialized(new ServletContextEvent(new MockServletContext()));
}
示例7: annotationConfigWAC
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
/**
* Ensure that ContextLoaderListener and AnnotationConfigApplicationContext interact nicely.
*/
@Test
public void annotationConfigWAC() {
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
ctx.scan("does.not.matter");
ContextLoaderListener cll = new ContextLoaderListener(ctx);
cll.contextInitialized(new ServletContextEvent(new MockServletContext()));
}
示例8: setUp
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
protected void setUp() throws Exception {
super.setUp();
sc = new MockServletContext("");
// initialize Spring
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
"classpath:/applicationContext-dao.xml, " +
"classpath:/applicationContext-service.xml, " +
"classpath:/applicationContext-resources.xml");
springListener = new ContextLoaderListener();
springListener.contextInitialized(new ServletContextEvent(sc));
listener = new StartupListener();
}
示例9: onSetUp
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
@Before
public void onSetUp() {
String appPackage = "org.musicrecital.webapp";
String appName = "app";
servletContext = new MockServletContext("");
// mock servlet settings
servletContext.addInitParameter(SpringConstants.USE_EXTERNAL_SPRING_CONTEXT, "true");
servletContext.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
StringUtils.arrayToCommaDelimitedString(locations)
);
// Start context loader w/ mock servlet prior to firing off registry
listener = new ContextLoaderListener();
listener.contextInitialized(new ServletContextEvent(servletContext));
tester = new PageTester(appPackage, appName, "src/main/webapp", AppTestModule.class) {
@Override
protected ModuleDef[] provideExtraModuleDefs() {
return new ModuleDef[]{new SpringModuleDef(servletContext)};
}
};
applicationContext = (WebApplicationContext)
servletContext.getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
fieldValues = new HashMap<String, String>();
smtpPort = smtpPort + (int) (Math.random() * 100);
// change the port on the mailSender so it doesn't conflict with an
// existing SMTP server on localhost
JavaMailSenderImpl mailSender = //(JavaMailSenderImpl)applicationContext.getBean("mailSender");
applicationContext.getBean(JavaMailSenderImpl.class);
mailSender.setPort(getSmtpPort());
mailSender.setHost("localhost");
}
示例10: setUp
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
/**
* @throws java.lang.Exception
*/
// @Before
public void setUp() throws Exception {
sc = new MockServletContext("");
// initialize Spring
sc.addInitParameter(ContextLoader.CONFIG_LOCATION_PARAM,
"classpath:/applicationContext-dao.xml, "
+ "classpath:/applicationContext-service.xml");
springListener = new ContextLoaderListener();
springListener.contextInitialized(new ServletContextEvent(sc));
listener = new StartupListener();
}
示例11: testLoadContext
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
public void testLoadContext() throws Throwable {
DaoTestConfigBean bean = new DaoTestConfigBean();
bean.afterPropertiesSet();
MockDatabase db = new MockDatabase(true);
DataSourceFactory.setInstance(db);
servletContext = new MockServletContext("file:src/main/webapp");
servletContext.addInitParameter(
"contextConfigLocation",
"classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " +
"classpath:/META-INF/opennms/applicationContext-soa.xml " +
"classpath:/META-INF/opennms/applicationContext-dao.xml " +
"classpath*:/META-INF/opennms/component-service.xml " +
"classpath*:/META-INF/opennms/component-dao.xml " +
"/WEB-INF/applicationContext-svclayer.xml " +
"/WEB-INF/applicationContext-spring-security.xml "
);
servletContext.addInitParameter("parentContextKey", "daoContext");
ServletContextEvent e = new ServletContextEvent(servletContext);
contextListener = new ContextLoaderListener();
contextListener.contextInitialized(e);
servletContext.setContextPath(contextPath);
servletConfig = new MockServletConfig(servletContext, "dispatcher");
servletConfig.addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
servletConfig.addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest");
try {
MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
filter = new OpenSessionInViewFilter();
filter.init(filterConfig);
} catch (ServletException se) {
throw se.getRootCause();
}
}
示例12: testLoadContext
import org.springframework.web.context.ContextLoaderListener; //导入方法依赖的package包/类
public void testLoadContext() throws Throwable {
DaoTestConfigBean bean = new DaoTestConfigBean();
bean.afterPropertiesSet();
MockDatabase db = new MockDatabase(true);
DataSourceFactory.setInstance(db);
servletContext = new MockServletContext("file:src/main/webapp");
servletContext.addInitParameter("contextConfigLocation",
"classpath:/org/opennms/web/rest/applicationContext-test.xml " +
"classpath:/META-INF/opennms/applicationContext-commonConfigs.xml " +
"classpath*:/META-INF/opennms/component-service.xml " +
"classpath*:/META-INF/opennms/component-dao.xml " +
"classpath:/META-INF/opennms/applicationContext-reportingCore.xml " +
"classpath:/org/opennms/web/svclayer/applicationContext-svclayer.xml " +
"classpath:/META-INF/opennms/applicationContext-reporting.xml " +
"/WEB-INF/applicationContext-spring-security.xml " +
"/WEB-INF/applicationContext-spring-webflow.xml"
);
servletContext.addInitParameter("parentContextKey", "daoContext");
ServletContextEvent e = new ServletContextEvent(servletContext);
contextListener = new ContextLoaderListener();
contextListener.contextInitialized(e);
servletContext.setContextPath(contextPath);
servletConfig = new MockServletConfig(servletContext, "dispatcher");
servletConfig.addInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig");
servletConfig.addInitParameter("com.sun.jersey.config.property.packages", "org.opennms.web.rest");
try {
MockFilterConfig filterConfig = new MockFilterConfig(servletContext, "openSessionInViewFilter");
filter = new OpenSessionInViewFilter();
filter.init(filterConfig);
dispatcher = new SpringServlet();
dispatcher.init(servletConfig);
} catch (ServletException se) {
throw se.getRootCause();
}
}