当前位置: 首页>>代码示例>>Java>>正文


Java AnnotationConfigWebApplicationContext.setServletContext方法代码示例

本文整理汇总了Java中org.springframework.web.context.support.AnnotationConfigWebApplicationContext.setServletContext方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationConfigWebApplicationContext.setServletContext方法的具体用法?Java AnnotationConfigWebApplicationContext.setServletContext怎么用?Java AnnotationConfigWebApplicationContext.setServletContext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.context.support.AnnotationConfigWebApplicationContext的用法示例。


在下文中一共展示了AnnotationConfigWebApplicationContext.setServletContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
@Override
public void onStartup(ServletContext servletContext)
		throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(MyMvcConfig.class);
	ctx.setServletContext(servletContext); // ②

	Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
}
 
开发者ID:longjiazuo,项目名称:springMvc4.x-project,代码行数:12,代码来源:WebInitializer.java

示例2: setup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
@Before
@SuppressWarnings("resource")
public void setup() throws Exception {
	this.filterChain = new MockFilterChain(this.servlet, new ResourceUrlEncodingFilter());

	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.setServletContext(new MockServletContext());
	context.register(WebConfig.class);
	context.refresh();

	this.request = new MockHttpServletRequest("GET", "/");
	this.request.setContextPath("/myapp");
	this.response = new MockHttpServletResponse();

	Object urlProvider = context.getBean(ResourceUrlProvider.class);
	this.request.setAttribute(ResourceUrlProviderExposingInterceptor.RESOURCE_URL_PROVIDER_ATTR, urlProvider);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:ResourceUrlProviderJavaConfigTests.java

示例3: testFromMappingName

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
@Test
public void testFromMappingName() throws Exception {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.setServletContext(new MockServletContext());
	context.register(WebConfig.class);
	context.refresh();

	this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
	this.request.setServerName("example.org");
	this.request.setServerPort(9999);
	this.request.setContextPath("/base");

	String mappingName = "PAC#getAddressesForCountry";
	String url = MvcUriComponentsBuilder.fromMappingName(mappingName).arg(0, "DE").buildAndExpand(123);
	assertEquals("/base/people/123/addresses/DE", url);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:MvcUriComponentsBuilderTests.java

示例4: testCustomShellProperties

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
@Test
public void testCustomShellProperties() throws Exception {
	MockEnvironment env = new MockEnvironment();
	env.setProperty("management.shell.auth.type", "simple");
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.setEnvironment(env);
	ctx.setServletContext(new MockServletContext());
	ctx.register(TestShellConfiguration.class);
	ctx.register(CrshAutoConfiguration.class);
	ctx.refresh();

	PluginLifeCycle lifeCycle = ctx.getBean(PluginLifeCycle.class);
	String uuid = lifeCycle.getConfig().getProperty("test.uuid");
	assertThat(uuid).isEqualTo(TestShellConfiguration.uuid);
	ctx.close();
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:17,代码来源:ShellPropertiesTests.java

示例5: runTest

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
private MockHttpServletResponse runTest(Class<?> configClass) throws ServletException, IOException {
	String basePath = "org/springframework/web/servlet/config/annotation";
	MockServletContext servletContext = new MockServletContext(basePath);
	MockServletConfig servletConfig = new MockServletConfig(servletContext);
	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
	MockHttpServletResponse response = new MockHttpServletResponse();

	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.register(configClass);
	context.setServletContext(servletContext);
	context.refresh();
	DispatcherServlet servlet = new DispatcherServlet(context);
	servlet.init(servletConfig);
	servlet.service(request, response);
	return response;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:ViewResolutionIntegrationTests.java

示例6: getToolContext

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
private ToolContext getToolContext(String toolboxConfigLocation) throws Exception {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.setServletContext(new MockServletContext());
	context.register(Config.class);
	context.refresh();
	EmbeddedVelocityToolboxView view = context
			.getBean(EmbeddedVelocityToolboxView.class);
	view.setToolboxConfigLocation(toolboxConfigLocation);
	Map<String, Object> model = new LinkedHashMap<String, Object>();
	HttpServletRequest request = new MockHttpServletRequest();
	HttpServletResponse response = new MockHttpServletResponse();
	ToolContext toolContext = (ToolContext) view.createVelocityContext(model, request,
			response);
	context.close();
	return toolContext;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:EmbeddedVelocityToolboxViewTests.java

示例7: createLayoutFromConfigClass

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
@Test
public void createLayoutFromConfigClass() throws Exception {
	AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
	context.register(ThymeleafAutoConfiguration.class,
			PropertyPlaceholderAutoConfiguration.class);
	MockServletContext servletContext = new MockServletContext();
	context.setServletContext(servletContext);
	context.refresh();
	ThymeleafView view = (ThymeleafView) context.getBean(ThymeleafViewResolver.class)
			.resolveViewName("view", Locale.UK);
	MockHttpServletResponse response = new MockHttpServletResponse();
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setAttribute(RequestContext.WEB_APPLICATION_CONTEXT_ATTRIBUTE, context);
	view.render(Collections.singletonMap("foo", "bar"), request, response);
	String result = response.getContentAsString();
	assertThat(result).contains("<title>Content</title>");
	assertThat(result).contains("<span>bar</span>");
	context.close();
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:20,代码来源:ThymeleafAutoConfigurationTests.java

示例8: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
public void onStartup(ServletContext servletContext)
			throws ServletException {
		AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
		ctx.register(WebAppConfig.class);
		servletContext.addListener(new ContextLoaderListener(ctx));
		
//		CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
//		characterEncodingFilter.setEncoding("UTF-8");
//		characterEncodingFilter.setForceEncoding(true);
//		javax.servlet.FilterRegistration.Dynamic filter = 
//				servletContext.addFilter("characterEncodingFilter", characterEncodingFilter);
//		filter.addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST), 
//				true, "/*");

		ctx.setServletContext(servletContext);

		javax.servlet.ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
		servlet.addMapping("/");
		servlet.setLoadOnStartup(1);
	}
 
开发者ID:tensorchen,项目名称:rrs,代码行数:21,代码来源:Initializer.java

示例9: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(MvcConfig.class);
    context.setServletContext(servletContext);
    ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(context));
    servlet.addMapping("/");
    servlet.setLoadOnStartup(1);
    servlet.setAsyncSupported(true);//开启异步方法支持
}
 
开发者ID:shuaishuaila,项目名称:java_springboot,代码行数:11,代码来源:WebInitializer.java

示例10: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    //这里是初始化Spring管理Bean工厂的方法,在Controller层编写时不要再使用老的获取Context方法再次初始化Bean。会抛出异常
    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    //将书写的SpringConfig类进行注册
    ctx.register(SpringConfigration.class);
    ctx.setServletContext(servletContext);
    //设置SpringMVC Servlet跳页面的方式为转发
    ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx));
    //servlet生效的方式为浏览器访问"/"也就是根下的访问路径
    servlet.addMapping("/");
    //在软件运行的一开始就让这个设置生效
    servlet.setLoadOnStartup(1);
}
 
开发者ID:okingjerryo,项目名称:WeiMusicCommunity-server,代码行数:15,代码来源:WebInitializer.java

示例11: initServlet

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
private static Servlet initServlet() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.register(MockDemoConfig.class);
    context.setServletContext(SERVLET_CONTEXT);
    DispatcherServlet servlet = new DispatcherServlet(context);
    ServletConfig servletConfig = new MockServletConfig();
    try {
        servlet.init(servletConfig);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return servlet;
}
 
开发者ID:intuit,项目名称:karate,代码行数:14,代码来源:MockSpringMvcServlet.java

示例12: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
public void onStartup(ServletContext container) throws ServletException {

        AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
        ctx.register(AppConfig.class);
        ctx.setServletContext(container);

        ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx));
        servlet.setLoadOnStartup(1);
        servlet.addMapping("/");
    }
 
开发者ID:xSzymo,项目名称:Spring-web-shop-project,代码行数:11,代码来源:AppInitializer.java

示例13: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
@Override
public void onStartup(ServletContext servletContext)
		throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(MyMvcConfig.class);
	ctx.setServletContext(servletContext); // ②

	Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // ③
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
}
 
开发者ID:longjiazuo,项目名称:springMvc4.x-project,代码行数:12,代码来源:WebInitializer.java

示例14: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
@Override
public void onStartup(ServletContext servletContext)
		throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(MyMvcConfig.class);
	ctx.setServletContext(servletContext); // ②

	Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3
	servlet.addMapping("/");
	servlet.setLoadOnStartup(1);
	servlet.setAsyncSupported(true);//①
}
 
开发者ID:longjiazuo,项目名称:springMvc4.x-project,代码行数:13,代码来源:WebInitializer.java

示例15: onStartup

import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; //导入方法依赖的package包/类
public void onStartup(ServletContext context) throws ServletException {
	AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
	ctx.register(GuastiWebConfig.class);
	ctx.setServletContext(context);
	ServletRegistration.Dynamic servlet = context.addServlet("dispatcher", new DispatcherServlet(ctx));
	servlet.setLoadOnStartup(1);
       servlet.addMapping("/");
}
 
开发者ID:andrea-colleoni,项目名称:corso-lutech,代码行数:9,代码来源:WebServletConfig.java


注:本文中的org.springframework.web.context.support.AnnotationConfigWebApplicationContext.setServletContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。