本文整理汇总了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