本文整理汇总了Java中org.springframework.web.context.support.GenericWebApplicationContext.refresh方法的典型用法代码示例。如果您正苦于以下问题:Java GenericWebApplicationContext.refresh方法的具体用法?Java GenericWebApplicationContext.refresh怎么用?Java GenericWebApplicationContext.refresh使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.web.context.support.GenericWebApplicationContext
的用法示例。
在下文中一共展示了GenericWebApplicationContext.refresh方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getApplicationContext
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
/**
* Provides a static, single instance of the application context. This method can be
* called repeatedly.
* <p/>
* If the configuration requested differs from one used previously, then the previously-created
* context is shut down.
*
* @return Returns an application context for the given configuration
*/
public synchronized static ConfigurableApplicationContext getApplicationContext(ServletContext servletContext, String[] configLocations)
{
AbstractApplicationContext ctx = (AbstractApplicationContext)BaseApplicationContextHelper.getApplicationContext(configLocations);
CmisServiceFactory factory = (CmisServiceFactory)ctx.getBean("CMISServiceFactory");
DefaultListableBeanFactory dlbf = new DefaultListableBeanFactory(ctx.getBeanFactory());
GenericWebApplicationContext gwac = new GenericWebApplicationContext(dlbf);
servletContext.setAttribute(GenericWebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, gwac);
servletContext.setAttribute(CmisRepositoryContextListener.SERVICES_FACTORY, factory);
gwac.setServletContext(servletContext);
gwac.refresh();
return gwac;
}
示例2: standardHandleMethod
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
@Test
public void standardHandleMethod() throws Exception {
DispatcherPortlet portlet = new DispatcherPortlet() {
@Override
protected ApplicationContext createPortletApplicationContext(ApplicationContext parent) throws BeansException {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(MyController.class));
wac.refresh();
return wac;
}
};
portlet.init(new MockPortletConfig());
MockRenderRequest request = new MockRenderRequest(PortletMode.VIEW);
MockRenderResponse response = new MockRenderResponse();
portlet.render(request, response);
assertEquals("test", response.getContentAsString());
}
示例3: commandProvidingFormControllerWithCustomEditor
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
@Test
public void commandProvidingFormControllerWithCustomEditor() throws Exception {
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller",
new RootBeanDefinition(MyCommandProvidingFormController.class));
wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
adapterDef.getPropertyValues().add("webBindingInitializer", new MyWebBindingInitializer());
wac.registerBeanDefinition("handlerAdapter", adapterDef);
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
request.addParameter("defaultName", "myDefaultName");
request.addParameter("age", "value2");
request.addParameter("date", "2007-10-02");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString());
}
示例4: configureExporterParametersWithEncodingFromPropertiesFile
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("deprecation")
public void configureExporterParametersWithEncodingFromPropertiesFile() throws Exception {
GenericWebApplicationContext ac = new GenericWebApplicationContext();
ac.setServletContext(new MockServletContext());
BeanDefinitionReader reader = new PropertiesBeanDefinitionReader(ac);
reader.loadBeanDefinitions(new ClassPathResource("view.properties", getClass()));
ac.refresh();
AbstractJasperReportsView view = (AbstractJasperReportsView) ac.getBean("report");
String encoding = (String) view.getConvertedExporterParameters().get(
net.sf.jasperreports.engine.export.JRHtmlExporterParameter.CHARACTER_ENCODING);
assertEquals("UTF-8", encoding);
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, ac);
view.render(getModel(), request, response);
assertEquals("Response content type is incorrect", "text/html;charset=UTF-8", response.getContentType());
}
示例5: initServlet
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
@SuppressWarnings("serial")
private void initServlet(final Class<?> controllerclass) throws ServletException {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
throws BeansException {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(controllerclass));
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setProxyTargetClass(true);
autoProxyCreator.setBeanFactory(wac.getBeanFactory());
wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
wac.getBeanFactory().registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor(true)));
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
}
示例6: doubles
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void doubles() throws Exception {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent)
throws BeansException {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(DoubleController.class));
RootBeanDefinition mappingDef = new RootBeanDefinition(DefaultAnnotationHandlerMapping.class);
mappingDef.getPropertyValues().add("useDefaultSuffixPattern", false);
wac.registerBeanDefinition("handlerMapping", mappingDef);
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/lat/1.2/long/3.4");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("latitude-1.2-longitude-3.4", response.getContentAsString());
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:UriTemplateServletAnnotationControllerTests.java
示例7: setUp
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
@Before
@SuppressWarnings("resource")
public void setUp() throws Exception {
GenericWebApplicationContext context = new GenericWebApplicationContext();
context.refresh();
resolver = new RequestHeaderMethodArgumentResolver(context.getBeanFactory());
Method method = getClass().getMethod("params", String.class, String[].class, String.class, String.class, Map.class);
paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 0);
paramNamedValueStringArray = new SynthesizingMethodParameter(method, 1);
paramSystemProperty = new SynthesizingMethodParameter(method, 2);
paramContextPath = new SynthesizingMethodParameter(method, 3);
paramNamedValueMap = new SynthesizingMethodParameter(method, 4);
servletRequest = new MockHttpServletRequest();
webRequest = new ServletWebRequest(servletRequest, new MockHttpServletResponse());
// Expose request to the current thread (for SpEL expressions)
RequestContextHolder.setRequestAttributes(webRequest);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:RequestHeaderMethodArgumentResolverTests.java
示例8: setUp
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
@Before
@SuppressWarnings("resource")
public void setUp() throws Exception {
GenericWebApplicationContext context = new GenericWebApplicationContext();
context.refresh();
resolver = new ExpressionValueMethodArgumentResolver(context.getBeanFactory());
Method method = getClass().getMethod("params", int.class, String.class, String.class);
paramSystemProperty = new MethodParameter(method, 0);
paramContextPath = new MethodParameter(method, 1);
paramNotSupported = new MethodParameter(method, 2);
webRequest = new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse());
// Expose request to the current thread (for SpEL expressions)
RequestContextHolder.setRequestAttributes(webRequest);
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:ExpressionValueMethodArgumentResolverTests.java
示例9: emptyRequestMapping
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
@Test
@SuppressWarnings("serial")
public void emptyRequestMapping() throws Exception {
servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(ControllerWithEmptyMapping.class));
RootBeanDefinition mbd = new RootBeanDefinition(ControllerClassNameHandlerMapping.class);
mbd.getPropertyValues().add("excludedPackages", null);
mbd.getPropertyValues().add("order", 0);
wac.registerBeanDefinition("mapping", mbd);
wac.registerBeanDefinition("mapping2", new RootBeanDefinition(DefaultAnnotationHandlerMapping.class));
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/servletannotationcontrollertests.controllerwithemptymapping");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("test", response.getContentAsString());
}
示例10: mavResolver
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
@Test
public void mavResolver() throws ServletException, IOException {
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(ModelAndViewResolverController.class));
RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
adapterDef.getPropertyValues().add("customModelAndViewResolver", new MyModelAndViewResolver());
wac.registerBeanDefinition("handlerAdapter", adapterDef);
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("myValue", response.getContentAsString());
}
示例11: createContext
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
private ApplicationContext createContext(ScopedProxyMode scopedProxyMode) {
GenericWebApplicationContext context = new GenericWebApplicationContext();
ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context);
scanner.setIncludeAnnotationConfig(false);
scanner.setBeanNameGenerator(new BeanNameGenerator() {
@Override
public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
return definition.getScope();
}
});
scanner.setScopedProxyMode(scopedProxyMode);
// Scan twice in order to find errors in the bean definition compatibility check.
scanner.scan(getClass().getPackage().getName());
scanner.scan(getClass().getPackage().getName());
context.refresh();
return context;
}
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:ClassPathBeanDefinitionScannerScopeIntegrationTests.java
示例12: unsupportedRequestBody
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
@Test
public void unsupportedRequestBody() throws ServletException, IOException {
@SuppressWarnings("serial") DispatcherServlet servlet = new DispatcherServlet() {
@Override
protected WebApplicationContext createWebApplicationContext(WebApplicationContext parent) {
GenericWebApplicationContext wac = new GenericWebApplicationContext();
wac.registerBeanDefinition("controller", new RootBeanDefinition(RequestResponseBodyController.class));
RootBeanDefinition adapterDef = new RootBeanDefinition(AnnotationMethodHandlerAdapter.class);
adapterDef.getPropertyValues().add("messageConverters", new ByteArrayHttpMessageConverter());
wac.registerBeanDefinition("handlerAdapter", adapterDef);
wac.refresh();
return wac;
}
};
servlet.init(new MockServletConfig());
MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
String requestBody = "Hello World";
request.setContent(requestBody.getBytes("UTF-8"));
request.addHeader("Content-Type", "application/pdf");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals(415, response.getStatus());
assertNotNull("No Accept response header set", response.getHeader("Accept"));
}
示例13: HandlerMethodAnnotationDetectionTests
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
public HandlerMethodAnnotationDetectionTests(final Class<?> controllerType, boolean useAutoProxy) {
GenericWebApplicationContext context = new GenericWebApplicationContext();
context.registerBeanDefinition("controller", new RootBeanDefinition(controllerType));
context.registerBeanDefinition("handlerMapping", new RootBeanDefinition(RequestMappingHandlerMapping.class));
context.registerBeanDefinition("handlerAdapter", new RootBeanDefinition(RequestMappingHandlerAdapter.class));
context.registerBeanDefinition("exceptionResolver", new RootBeanDefinition(ExceptionHandlerExceptionResolver.class));
if (useAutoProxy) {
DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
autoProxyCreator.setBeanFactory(context.getBeanFactory());
context.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
context.registerBeanDefinition("controllerAdvice", new RootBeanDefinition(ControllerAdvisor.class));
}
context.refresh();
this.handlerMapping = context.getBean(RequestMappingHandlerMapping.class);
this.handlerAdapter = context.getBean(RequestMappingHandlerAdapter.class);
this.exceptionResolver = context.getBean(ExceptionHandlerExceptionResolver.class);
context.close();
}
示例14: createWebApplicationContext
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
protected WebApplicationContext createWebApplicationContext(ServletContext sc, ApplicationContext parent)
{
GenericWebApplicationContext wac = (GenericWebApplicationContext) BeanUtils.instantiateClass(GenericWebApplicationContext.class);
// Assign the best possible id value.
wac.setId(ConfigurableWebApplicationContext.APPLICATION_CONTEXT_ID_PREFIX + contextPath);
wac.setParent(parent);
wac.setServletContext(sc);
wac.refresh();
return wac;
}
示例15: initApplicationContext
import org.springframework.web.context.support.GenericWebApplicationContext; //导入方法依赖的package包/类
private ConfigurablePortletApplicationContext initApplicationContext(String scope) {
MockServletContext sc = new MockServletContext();
GenericWebApplicationContext rac = new GenericWebApplicationContext(sc);
rac.refresh();
PortletContext pc = new ServletWrappingPortletContext(sc);
StaticPortletApplicationContext ac = new StaticPortletApplicationContext();
ac.setParent(rac);
ac.setPortletContext(pc);
GenericBeanDefinition bd = new GenericBeanDefinition();
bd.setBeanClass(DerivedTestBean.class);
bd.setScope(scope);
ac.registerBeanDefinition(NAME, bd);
ac.refresh();
return ac;
}