本文整理汇总了Java中org.springframework.web.context.support.StaticWebApplicationContext.refresh方法的典型用法代码示例。如果您正苦于以下问题:Java StaticWebApplicationContext.refresh方法的具体用法?Java StaticWebApplicationContext.refresh怎么用?Java StaticWebApplicationContext.refresh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.support.StaticWebApplicationContext
的用法示例。
在下文中一共展示了StaticWebApplicationContext.refresh方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
MockServletContext servletContext = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(servletContext);
wac.refresh();
request = new MockHttpServletRequest();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
response = new MockHttpServletResponse();
renderer = mock(Renderer.class);
view = new TilesView();
view.setServletContext(servletContext);
view.setRenderer(renderer);
view.setUrl(VIEW_PATH);
view.afterPropertiesSet();
}
示例2: testDelegatingFilterProxyWithFilterName
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
public void testDelegatingFilterProxyWithFilterName() throws ServletException, IOException {
ServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.registerSingleton("targetFilter", MockFilter.class);
wac.refresh();
sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter");
MockFilterConfig proxyConfig = new MockFilterConfig(sc, "targetFilter");
DelegatingFilterProxy filterProxy = new DelegatingFilterProxy();
filterProxy.init(proxyConfig);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
filterProxy.doFilter(request, response, null);
assertNull(targetFilter.filterConfig);
assertEquals(Boolean.TRUE, request.getAttribute("called"));
filterProxy.destroy();
assertNull(targetFilter.filterConfig);
}
示例3: updateTargetUrl
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
public void updateTargetUrl() throws Exception {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.registerSingleton("requestDataValueProcessor", RequestDataValueProcessorWrapper.class);
wac.setServletContext(new MockServletContext());
wac.refresh();
RequestDataValueProcessor mockProcessor = mock(RequestDataValueProcessor.class);
wac.getBean(RequestDataValueProcessorWrapper.class).setRequestDataValueProcessor(mockProcessor);
RedirectView rv = new RedirectView();
rv.setApplicationContext(wac); // Init RedirectView with WebAppCxt
rv.setUrl("/path");
MockHttpServletRequest request = createRequest();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
HttpServletResponse response = new MockHttpServletResponse();
given(mockProcessor.processUrl(request, "/path")).willReturn("/path?key=123");
rv.render(new ModelMap(), request, response);
verify(mockProcessor).processUrl(request, "/path");
}
示例4: testXmlViewResolverDefaultLocation
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
public void testXmlViewResolverDefaultLocation() {
StaticWebApplicationContext wac = new StaticWebApplicationContext() {
@Override
protected Resource getResourceByPath(String path) {
assertTrue("Correct default location", XmlViewResolver.DEFAULT_LOCATION.equals(path));
return super.getResourceByPath(path);
}
};
wac.setServletContext(new MockServletContext());
wac.refresh();
XmlViewResolver vr = new XmlViewResolver();
try {
vr.setApplicationContext(wac);
vr.afterPropertiesSet();
fail("Should have thrown BeanDefinitionStoreException");
}
catch (BeanDefinitionStoreException ex) {
// expected
}
}
示例5: setUp
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
final Template expectedTemplate = new Template();
VelocityConfig vc = new VelocityConfig() {
@Override
public VelocityEngine getVelocityEngine() {
return new TestVelocityEngine("test.vm", expectedTemplate);
}
};
wac.getDefaultListableBeanFactory().registerSingleton("velocityConfigurer", vc);
wac.refresh();
request = new MockHttpServletRequest();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
response = new MockHttpServletResponse();
}
示例6: testVelocityViewResolverWithToolbox
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
public void testVelocityViewResolverWithToolbox() throws Exception {
VelocityConfig vc = new VelocityConfig() {
@Override
public VelocityEngine getVelocityEngine() {
return new TestVelocityEngine("prefix_test_suffix", new Template());
}
};
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.getBeanFactory().registerSingleton("configurer", vc);
wac.refresh();
String toolbox = "org/springframework/web/servlet/view/velocity/toolbox.xml";
VelocityViewResolver vr = new VelocityViewResolver();
vr.setPrefix("prefix_");
vr.setSuffix("_suffix");
vr.setToolboxConfigLocation(toolbox);
vr.setApplicationContext(wac);
View view = vr.resolveViewName("test", Locale.CANADA);
assertEquals("Correct view class", VelocityToolboxView.class, view.getClass());
assertEquals("Correct URL", "prefix_test_suffix", ((VelocityView) view).getUrl());
assertEquals("Correct toolbox", toolbox, ((VelocityToolboxView) view).getToolboxConfigLocation());
}
示例7: actionSupportWithContextLoaderPlugIn
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void actionSupportWithContextLoaderPlugIn() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.addMessage("test", Locale.getDefault(), "testmessage");
final ServletContext servletContext = new MockServletContext();
wac.setServletContext(servletContext);
wac.refresh();
servletContext.setAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX, wac);
ActionServlet actionServlet = new ActionServlet() {
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
ActionSupport action = new ActionSupport() {
};
action.setServlet(actionServlet);
assertEquals(wac, action.getWebApplicationContext());
assertEquals(servletContext, action.getServletContext());
assertEquals("testmessage", action.getMessageSourceAccessor().getMessage("test"));
action.setServlet(null);
}
示例8: actionSupportWithRootContext
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void actionSupportWithRootContext() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.addMessage("test", Locale.getDefault(), "testmessage");
final ServletContext servletContext = new MockServletContext();
wac.setServletContext(servletContext);
wac.refresh();
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
ActionServlet actionServlet = new ActionServlet() {
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
ActionSupport action = new ActionSupport() {
};
action.setServlet(actionServlet);
assertEquals(wac, action.getWebApplicationContext());
assertEquals(servletContext, action.getServletContext());
assertEquals("testmessage", action.getMessageSourceAccessor().getMessage("test"));
action.setServlet(null);
}
示例9: dispatchActionSupportWithContextLoaderPlugIn
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void dispatchActionSupportWithContextLoaderPlugIn() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.addMessage("test", Locale.getDefault(), "testmessage");
final ServletContext servletContext = new MockServletContext();
wac.setServletContext(servletContext);
wac.refresh();
servletContext.setAttribute(ContextLoaderPlugIn.SERVLET_CONTEXT_PREFIX, wac);
ActionServlet actionServlet = new ActionServlet() {
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
DispatchActionSupport action = new DispatchActionSupport() {
};
action.setServlet(actionServlet);
assertEquals(wac, action.getWebApplicationContext());
assertEquals(servletContext, action.getServletContext());
assertEquals("testmessage", action.getMessageSourceAccessor().getMessage("test"));
action.setServlet(null);
}
示例10: dispatchActionSupportWithRootContext
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void dispatchActionSupportWithRootContext() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.addMessage("test", Locale.getDefault(), "testmessage");
final ServletContext servletContext = new MockServletContext();
wac.setServletContext(servletContext);
wac.refresh();
servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
ActionServlet actionServlet = new ActionServlet() {
@Override
public ServletContext getServletContext() {
return servletContext;
}
};
DispatchActionSupport action = new DispatchActionSupport() {
};
action.setServlet(actionServlet);
assertEquals(wac, action.getWebApplicationContext());
assertEquals(servletContext, action.getServletContext());
assertEquals("testmessage", action.getMessageSourceAccessor().getMessage("test"));
action.setServlet(null);
}
示例11: setUp
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Override
public void setUp() throws Exception {
wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
final Template expectedTemplate = new Template();
VelocityConfig vc = new VelocityConfig() {
@Override
public VelocityEngine getVelocityEngine() {
return new TestVelocityEngine(TEMPLATE_FILE, expectedTemplate);
}
};
wac.getDefaultListableBeanFactory().registerSingleton("velocityConfigurer", vc);
wac.refresh();
request = new MockHttpServletRequest();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
response = new MockHttpServletResponse();
}
示例12: testDelegatingVariableResolver
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
public void testDelegatingVariableResolver() {
final StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.registerSingleton("bean1", TestBean.class, null);
wac.registerSingleton("var1", TestBean.class, null);
wac.refresh();
TestBean bean1 = (TestBean) wac.getBean("bean1");
// We need to override the getWebApplicationContext method here:
// FacesContext and ExternalContext are hard to mock.
DelegatingVariableResolver resolver = new DelegatingVariableResolver(new OriginalVariableResolver()) {
@Override
protected WebApplicationContext getWebApplicationContext(FacesContext facesContext) {
return wac;
}
};
assertEquals(bean1, resolver.resolveVariable(null, "bean1"));
assertEquals("val1", resolver.resolveVariable(null, "var1"));
}
示例13: setUp
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
// final Template expectedTemplate = new Template();
fc = new FreeMarkerConfigurer();
fc.setTemplateLoaderPaths(new String[] { "classpath:/", "file://" + System.getProperty("java.io.tmpdir") });
fc.afterPropertiesSet();
wac.getDefaultListableBeanFactory().registerSingleton("freeMarkerConfigurer", fc);
wac.refresh();
request = new MockHttpServletRequest();
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
response = new MockHttpServletResponse();
}
示例14: testDelegatingFilterProxyWithTargetFilterLifecycle
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
public void testDelegatingFilterProxyWithTargetFilterLifecycle() throws ServletException, IOException {
ServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.registerSingleton("targetFilter", MockFilter.class);
wac.refresh();
sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
MockFilter targetFilter = (MockFilter) wac.getBean("targetFilter");
MockFilterConfig proxyConfig = new MockFilterConfig(sc);
proxyConfig.addInitParameter("targetBeanName", "targetFilter");
proxyConfig.addInitParameter("targetFilterLifecycle", "true");
DelegatingFilterProxy filterProxy = new DelegatingFilterProxy();
filterProxy.init(proxyConfig);
assertEquals(proxyConfig, targetFilter.filterConfig);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
filterProxy.doFilter(request, response, null);
assertEquals(proxyConfig, targetFilter.filterConfig);
assertEquals(Boolean.TRUE, request.getAttribute("called"));
filterProxy.destroy();
assertNull(targetFilter.filterConfig);
}
示例15: testDelegatingFilterProxyInjectedPreferred
import org.springframework.web.context.support.StaticWebApplicationContext; //导入方法依赖的package包/类
@Test
public void testDelegatingFilterProxyInjectedPreferred() throws ServletException, IOException {
ServletContext sc = new MockServletContext();
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(sc);
wac.refresh();
sc.setAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.dispatcher", wac);
StaticWebApplicationContext injectedWac = new StaticWebApplicationContext();
injectedWac.setServletContext(sc);
String beanName = "targetFilter";
injectedWac.registerSingleton(beanName, MockFilter.class);
injectedWac.refresh();
MockFilter targetFilter = (MockFilter) injectedWac.getBean(beanName);
DelegatingFilterProxy filterProxy = new DelegatingFilterProxy(beanName, injectedWac);
MockHttpServletRequest request = new MockHttpServletRequest();
MockHttpServletResponse response = new MockHttpServletResponse();
filterProxy.doFilter(request, response, null);
assertNull(targetFilter.filterConfig);
assertEquals(Boolean.TRUE, request.getAttribute("called"));
filterProxy.destroy();
assertNull(targetFilter.filterConfig);
}