當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。