當前位置: 首頁>>代碼示例>>Java>>正文


Java ApplicationContextInitializer類代碼示例

本文整理匯總了Java中org.springframework.context.ApplicationContextInitializer的典型用法代碼示例。如果您正苦於以下問題:Java ApplicationContextInitializer類的具體用法?Java ApplicationContextInitializer怎麽用?Java ApplicationContextInitializer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ApplicationContextInitializer類屬於org.springframework.context包,在下文中一共展示了ApplicationContextInitializer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: pathVarsInModel

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void pathVarsInModel() throws Exception {
	final Map<String, Object> pathVars = new HashMap<String, Object>();
	pathVars.put("hotel", "42");
	pathVars.put("booking", 21);
	pathVars.put("other", "other");

	WebApplicationContext wac =
		initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
			@Override
			public void initialize(GenericWebApplicationContext context) {
				RootBeanDefinition beanDef = new RootBeanDefinition(ModelValidatingViewResolver.class);
				beanDef.getConstructorArgumentValues().addGenericArgumentValue(pathVars);
				context.registerBeanDefinition("viewResolver", beanDef);
			}
		}, ViewRenderingController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/hotels/42;q=1,2/bookings/21-other;q=3;r=R");
	getServlet().service(request, new MockHttpServletResponse());

	ModelValidatingViewResolver resolver = wac.getBean(ModelValidatingViewResolver.class);
	assertEquals(3, resolver.validatedAttrCount);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:UriTemplateServletAnnotationControllerHandlerMethodTests.java

示例2: defaultExpressionParameters

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void defaultExpressionParameters() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext context) {
			RootBeanDefinition ppc = new RootBeanDefinition(PropertyPlaceholderConfigurer.class);
			ppc.getPropertyValues().add("properties", "myKey=foo");
			context.registerBeanDefinition("ppc", ppc);
		}
	}, DefaultExpressionValueParamController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myApp/myPath.do");
	request.setContextPath("/myApp");
	MockHttpServletResponse response = new MockHttpServletResponse();
	System.setProperty("myHeader", "bar");
	try {
		getServlet().service(request, response);
	}
	finally {
		System.clearProperty("myHeader");
	}
	assertEquals("foo-bar-/myApp", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例3: typeNestedSetBinding

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void typeNestedSetBinding() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext context) {
			RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
			csDef.getPropertyValues().add("converters", new TestBeanConverter());
			RootBeanDefinition wbiDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
			wbiDef.getPropertyValues().add("conversionService", csDef);
			RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
			adapterDef.getPropertyValues().add("webBindingInitializer", wbiDef);
			context.registerBeanDefinition("handlerAdapter", adapterDef);
		}
	}, NestedSetController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
	request.addParameter("testBeanSet", new String[] {"1", "2"});
	MockHttpServletResponse response = new MockHttpServletResponse();
	getServlet().service(request, response);
	assertEquals("[1, 2]-org.springframework.tests.sample.beans.TestBean", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例4: pathVariableWithCustomConverter

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void pathVariableWithCustomConverter() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext context) {
			RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
			csDef.getPropertyValues().add("converters", new AnnotatedExceptionRaisingConverter());
			RootBeanDefinition wbiDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
			wbiDef.getPropertyValues().add("conversionService", csDef);
			RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
			adapterDef.getPropertyValues().add("webBindingInitializer", wbiDef);
			context.registerBeanDefinition("handlerAdapter", adapterDef);
		}
	}, PathVariableWithCustomConverterController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath/1");
	MockHttpServletResponse response = new MockHttpServletResponse();
	getServlet().service(request, response);
	assertEquals(404, response.getStatus());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例5: emptyParameterListHandleMethod

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void emptyParameterListHandleMethod() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext context) {
			RootBeanDefinition vrDef = new RootBeanDefinition(InternalResourceViewResolver.class);
			vrDef.getPropertyValues().add("suffix", ".jsp");
			context.registerBeanDefinition("viewResolver", vrDef);
		}
	}, EmptyParameterListHandlerMethodController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/emptyParameterListHandler");
	MockHttpServletResponse response = new MockHttpServletResponse();

	EmptyParameterListHandlerMethodController.called = false;
	getServlet().service(request, response);
	assertTrue(EmptyParameterListHandlerMethodController.called);
	assertEquals("", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例6: formController

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void formController() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
		}
	}, MyFormController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
	request.addParameter("name", "name1");
	request.addParameter("age", "value2");
	MockHttpServletResponse response = new MockHttpServletResponse();
	getServlet().service(request, response);
	assertEquals("myView-name1-typeMismatch-tb1-myValue", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例7: modelFormController

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void modelFormController() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
		}
	}, MyModelFormController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
	request.addParameter("name", "name1");
	request.addParameter("age", "value2");
	MockHttpServletResponse response = new MockHttpServletResponse();
	getServlet().service(request, response);
	assertEquals("myPath-name1-typeMismatch-tb1-myValue-yourValue", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:17,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例8: proxiedFormController

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void proxiedFormController() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
			DefaultAdvisorAutoProxyCreator autoProxyCreator = new DefaultAdvisorAutoProxyCreator();
			autoProxyCreator.setBeanFactory(wac.getBeanFactory());
			wac.getBeanFactory().addBeanPostProcessor(autoProxyCreator);
			wac.getBeanFactory()
					.registerSingleton("advisor", new DefaultPointcutAdvisor(new SimpleTraceInterceptor()));
		}
	}, MyFormController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("GET", "/myPath.do");
	request.addParameter("name", "name1");
	request.addParameter("age", "value2");
	MockHttpServletResponse response = new MockHttpServletResponse();
	getServlet().service(request, response);
	assertEquals("myView-name1-typeMismatch-tb1-myValue", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例9: commandProvidingFormControllerWithCustomEditor

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void commandProvidingFormControllerWithCustomEditor() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
			RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
			adapterDef.getPropertyValues().add("webBindingInitializer", new MyWebBindingInitializer());
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
		}
	}, MyCommandProvidingFormController.class);

	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();
	getServlet().service(request, response);
	assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例10: binderInitializingCommandProvidingFormController

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void binderInitializingCommandProvidingFormController() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
		}
	}, MyBinderInitializingCommandProvidingFormController.class);

	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();
	getServlet().service(request, response);
	assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例11: specificBinderInitializingCommandProvidingFormController

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void specificBinderInitializingCommandProvidingFormController() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			wac.registerBeanDefinition("viewResolver", new RootBeanDefinition(TestViewResolver.class));
		}
	}, MySpecificBinderInitializingCommandProvidingFormController.class);

	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();
	getServlet().service(request, response);
	assertEquals("myView-String:myDefaultName-typeMismatch-tb1-myOriginalValue", response.getContentAsString());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:18,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例12: responseBodyNoAcceptableMediaType

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void responseBodyNoAcceptableMediaType() throws ServletException, IOException {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
			StringHttpMessageConverter converter = new StringHttpMessageConverter();
			adapterDef.getPropertyValues().add("messageConverters", converter);
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
		}
	}, RequestResponseBodyProducesController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
	String requestBody = "Hello World";
	request.setContent(requestBody.getBytes("UTF-8"));
	request.addHeader("Content-Type", "text/plain; charset=utf-8");
	request.addHeader("Accept", "application/pdf, application/msword");
	MockHttpServletResponse response = new MockHttpServletResponse();
	getServlet().service(request, response);
	assertEquals(406, response.getStatus());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:22,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例13: unsupportedRequestBody

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void unsupportedRequestBody() throws ServletException, IOException {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
			adapterDef.getPropertyValues().add("messageConverters", new ByteArrayHttpMessageConverter());
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
		}
	}, RequestResponseBodyController.class);

	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();
	getServlet().service(request, response);
	assertEquals(415, response.getStatus());
	assertNotNull("No Accept response header set", response.getHeader("Accept"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例14: badRequestRequestBody

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void badRequestRequestBody() throws ServletException, IOException {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
			adapterDef.getPropertyValues().add("messageConverters", new NotReadableMessageConverter());
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
		}
	}, RequestResponseBodyController.class);

	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();
	getServlet().service(request, response);
	assertEquals("Invalid response status code", HttpServletResponse.SC_BAD_REQUEST, response.getStatus());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:20,代碼來源:ServletAnnotationControllerHandlerMethodTests.java

示例15: overlappingMessageConvertersRequestBody

import org.springframework.context.ApplicationContextInitializer; //導入依賴的package包/類
@Test
public void overlappingMessageConvertersRequestBody() throws ServletException, IOException {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
			List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
			messageConverters.add(new StringHttpMessageConverter());
			messageConverters
					.add(new SimpleMessageConverter(new MediaType("application","json"), MediaType.ALL));
			adapterDef.getPropertyValues().add("messageConverters", messageConverters);
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
		}
	}, RequestResponseBodyController.class);

	MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/something");
	request.setContent("Hello World".getBytes("UTF-8"));
	request.addHeader("Content-Type", "text/plain; charset=utf-8");
	request.addHeader("Accept", "application/json, text/javascript, */*");
	MockHttpServletResponse response = new MockHttpServletResponse();
	getServlet().service(request, response);
	assertEquals("Invalid content-type", "application/json", response.getHeader("Content-Type"));
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:ServletAnnotationControllerHandlerMethodTests.java


注:本文中的org.springframework.context.ApplicationContextInitializer類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。