本文整理汇总了Java中org.springframework.web.context.support.StaticWebApplicationContext类的典型用法代码示例。如果您正苦于以下问题:Java StaticWebApplicationContext类的具体用法?Java StaticWebApplicationContext怎么用?Java StaticWebApplicationContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StaticWebApplicationContext类属于org.springframework.web.context.support包,在下文中一共展示了StaticWebApplicationContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setListableBeanFactory
import org.springframework.web.context.support.StaticWebApplicationContext; //导入依赖的package包/类
private void setListableBeanFactory() {
ListableBeanFactory beanFactory = new StaticWebApplicationContext() {
@Override
public String[] getBeanNamesForType(Class<?> type,
boolean includeNonSingletons, boolean allowEagerInit) {
if (type.isAssignableFrom(
ResourceServerTokenServicesConfiguration.class)) {
return new String[] { "ResourceServerTokenServicesConfiguration" };
}
return new String[0];
}
};
this.properties.setBeanFactory(beanFactory);
}
开发者ID:spring-projects,项目名称:spring-security-oauth2-boot,代码行数:17,代码来源:ResourceServerPropertiesTests.java
示例2: 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();
}
示例3: testBeanNameViewResolver
import org.springframework.web.context.support.StaticWebApplicationContext; //导入依赖的package包/类
@Test
public void testBeanNameViewResolver() throws ServletException {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
MutablePropertyValues pvs1 = new MutablePropertyValues();
pvs1.addPropertyValue(new PropertyValue("url", "/example1.jsp"));
wac.registerSingleton("example1", InternalResourceView.class, pvs1);
MutablePropertyValues pvs2 = new MutablePropertyValues();
pvs2.addPropertyValue(new PropertyValue("url", "/example2.jsp"));
wac.registerSingleton("example2", JstlView.class, pvs2);
BeanNameViewResolver vr = new BeanNameViewResolver();
vr.setApplicationContext(wac);
wac.refresh();
View view = vr.resolveViewName("example1", Locale.getDefault());
assertEquals("Correct view class", InternalResourceView.class, view.getClass());
assertEquals("Correct URL", "/example1.jsp", ((InternalResourceView) view).getUrl());
view = vr.resolveViewName("example2", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "/example2.jsp", ((JstlView) view).getUrl());
}
示例4: doTestUrlBasedViewResolverWithPrefixes
import org.springframework.web.context.support.StaticWebApplicationContext; //导入依赖的package包/类
private void doTestUrlBasedViewResolverWithPrefixes(UrlBasedViewResolver vr) throws Exception {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
wac.refresh();
vr.setPrefix("/WEB-INF/");
vr.setSuffix(".jsp");
vr.setApplicationContext(wac);
View view = vr.resolveViewName("example1", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "/WEB-INF/example1.jsp", ((InternalResourceView) view).getUrl());
view = vr.resolveViewName("example2", Locale.getDefault());
assertEquals("Correct view class", JstlView.class, view.getClass());
assertEquals("Correct URL", "/WEB-INF/example2.jsp", ((InternalResourceView) view).getUrl());
view = vr.resolveViewName("redirect:myUrl", Locale.getDefault());
assertEquals("Correct view class", RedirectView.class, view.getClass());
assertEquals("Correct URL", "myUrl", ((RedirectView) view).getUrl());
view = vr.resolveViewName("forward:myUrl", Locale.getDefault());
assertEquals("Correct view class", InternalResourceView.class, view.getClass());
assertEquals("Correct URL", "myUrl", ((InternalResourceView) view).getUrl());
}
示例5: 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
}
}
示例6: testCacheRemoval
import org.springframework.web.context.support.StaticWebApplicationContext; //导入依赖的package包/类
@Test
public void testCacheRemoval() throws Exception {
StaticWebApplicationContext wac = new StaticWebApplicationContext();
wac.setServletContext(new MockServletContext());
wac.refresh();
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setViewClass(JstlView.class);
vr.setApplicationContext(wac);
View view = vr.resolveViewName("example1", Locale.getDefault());
View cached = vr.resolveViewName("example1", Locale.getDefault());
if (view != cached) {
fail("Caching doesn't work");
}
vr.removeFromCache("example1", Locale.getDefault());
cached = vr.resolveViewName("example1", Locale.getDefault());
if (view == cached) {
// the chance of having the same reference (hashCode) twice if negligible).
fail("View wasn't removed from cache");
}
}
示例7: nestedViewResolverIsNotSpringBean
import org.springframework.web.context.support.StaticWebApplicationContext; //导入依赖的package包/类
@Test
public void nestedViewResolverIsNotSpringBean() throws Exception {
StaticWebApplicationContext webAppContext = new StaticWebApplicationContext();
webAppContext.setServletContext(new MockServletContext());
webAppContext.refresh();
InternalResourceViewResolver nestedResolver = new InternalResourceViewResolver();
nestedResolver.setApplicationContext(webAppContext);
nestedResolver.setViewClass(InternalResourceView.class);
viewResolver.setViewResolvers(new ArrayList<ViewResolver>(Arrays.asList(nestedResolver)));
FixedContentNegotiationStrategy fixedStrategy = new FixedContentNegotiationStrategy(MediaType.TEXT_HTML);
viewResolver.setContentNegotiationManager(new ContentNegotiationManager(fixedStrategy));
viewResolver.afterPropertiesSet();
String viewName = "view";
Locale locale = Locale.ENGLISH;
View result = viewResolver.resolveViewName(viewName, locale);
assertNotNull("Invalid view", result);
}
示例8: 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("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();
}
示例9: 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();
}
示例10: 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());
}
示例11: 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(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: 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");
}
示例13: controllerAdvice
import org.springframework.web.context.support.StaticWebApplicationContext; //导入依赖的package包/类
@Test
public void controllerAdvice() throws Exception {
StaticWebApplicationContext cxt = new StaticWebApplicationContext();
cxt.registerSingleton("exceptionHandler", ApplicationExceptionHandler.class);
cxt.refresh();
ExceptionHandlerExceptionResolver resolver = new ExceptionHandlerExceptionResolver();
resolver.setApplicationContext(cxt);
resolver.afterPropertiesSet();
ServletRequestBindingException ex = new ServletRequestBindingException("message");
resolver.resolveException(this.servletRequest, this.servletResponse, null, ex);
assertEquals(400, this.servletResponse.getStatus());
assertEquals("error content", this.servletResponse.getContentAsString());
assertEquals("someHeaderValue", this.servletResponse.getHeader("someHeader"));
}
示例14: mappedInterceptors
import org.springframework.web.context.support.StaticWebApplicationContext; //导入依赖的package包/类
@Test
public void mappedInterceptors() throws Exception {
String path = "/foo";
HandlerInterceptor interceptor = new HandlerInterceptorAdapter() {};
MappedInterceptor mappedInterceptor = new MappedInterceptor(new String[] {path}, interceptor);
TestRequestMappingInfoHandlerMapping hm = new TestRequestMappingInfoHandlerMapping();
hm.registerHandler(new TestController());
hm.setInterceptors(new Object[] { mappedInterceptor });
hm.setApplicationContext(new StaticWebApplicationContext());
HandlerExecutionChain chain = hm.getHandler(new MockHttpServletRequest("GET", path));
assertNotNull(chain);
assertNotNull(chain.getInterceptors());
assertSame(interceptor, chain.getInterceptors()[0]);
chain = hm.getHandler(new MockHttpServletRequest("GET", "/invalid"));
assertNull(chain);
}
示例15: getCorsConfigWithBeanNameHandler
import org.springframework.web.context.support.StaticWebApplicationContext; //导入依赖的package包/类
@Test
public void getCorsConfigWithBeanNameHandler() throws Exception {
String key = "foo";
String beanName = "handler1";
StaticWebApplicationContext context = new StaticWebApplicationContext();
context.registerSingleton(beanName, MyHandler.class);
this.mapping.setApplicationContext(context);
this.mapping.registerMapping(key, beanName, this.method1);
HandlerMethod handlerMethod = this.mapping.getHandlerInternal(new MockHttpServletRequest("GET", key));
CorsConfiguration config = this.mapping.getMappingRegistry().getCorsConfiguration(handlerMethod);
assertNotNull(config);
assertEquals("http://" + beanName.hashCode() + this.method1.getName(), config.getAllowedOrigins().get(0));
}