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


Java ConfigurableWebBindingInitializer类代码示例

本文整理汇总了Java中org.springframework.web.bind.support.ConfigurableWebBindingInitializer的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableWebBindingInitializer类的具体用法?Java ConfigurableWebBindingInitializer怎么用?Java ConfigurableWebBindingInitializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
@Test
@Deprecated
public void test() throws Exception {
	AnnotationMethodHandlerAdapter adapter = new AnnotationMethodHandlerAdapter();
	ConfigurableWebBindingInitializer binder = new ConfigurableWebBindingInitializer();
	GenericConversionService service = new DefaultConversionService();
	service.addConverter(new ColorConverter());
	binder.setConversionService(service);
	adapter.setWebBindingInitializer(binder);
	Spr7766Controller controller = new Spr7766Controller();
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/colors");
	request.setPathInfo("/colors");
	request.addParameter("colors", "#ffffff,000000");
	MockHttpServletResponse response = new MockHttpServletResponse();
	adapter.handle(request, response, controller);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:Spr7766Tests.java

示例2: setup

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
@Before
public void setup() throws Exception {
	ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
	bindingInitializer.setValidator(new StubValidator());

	List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<HandlerMethodArgumentResolver>();
	customResolvers.add(new ServletWebArgumentResolverAdapter(new ColorArgumentResolver()));

	GenericWebApplicationContext context = new GenericWebApplicationContext();
	context.refresh();

	handlerAdapter = new RequestMappingHandlerAdapter();
	handlerAdapter.setWebBindingInitializer(bindingInitializer);
	handlerAdapter.setCustomArgumentResolvers(customResolvers);
	handlerAdapter.setApplicationContext(context);
	handlerAdapter.setBeanFactory(context.getBeanFactory());
	handlerAdapter.afterPropertiesSet();

	request = new MockHttpServletRequest();
	response = new MockHttpServletResponse();

	request.setMethod("POST");

	// Expose request to the current thread (for SpEL expressions)
	RequestContextHolder.setRequestAttributes(new ServletWebRequest(request));
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:27,代码来源:RequestMappingHandlerAdapterIntegrationTests.java

示例3: typeNestedSetBinding

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的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.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的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: parameterCsvAsStringArray

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
@Test
public void parameterCsvAsStringArray() throws Exception {
	initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
		@Override
		public void initialize(GenericWebApplicationContext wac) {
			RootBeanDefinition csDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
			RootBeanDefinition wbiDef = new RootBeanDefinition(ConfigurableWebBindingInitializer.class);
			wbiDef.getPropertyValues().add("conversionService", csDef);
			RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
			adapterDef.getPropertyValues().add("webBindingInitializer", wbiDef);
			wac.registerBeanDefinition("handlerAdapter", adapterDef);
		}
	}, CsvController.class);

	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setRequestURI("/integerArray");
	request.setMethod("POST");
	request.addParameter("content", "1,2");
	MockHttpServletResponse response = new MockHttpServletResponse();
	getServlet().service(request, response);
	assertEquals("1-2", response.getContentAsString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:23,代码来源:ServletAnnotationControllerHandlerMethodTests.java

示例6: setUp

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	this.processor = new ServletModelAttributeMethodProcessor(false);

	Method method = getClass().getDeclaredMethod("modelAttribute",
			TestBean.class, TestBeanWithoutStringConstructor.class, Optional.class);

	this.testBeanModelAttr = new MethodParameter(method, 0);
	this.testBeanWithoutStringConstructorModelAttr = new MethodParameter(method, 1);
	this.testBeanWithOptionalModelAttr = new MethodParameter(method, 2);

	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(new DefaultConversionService());

	this.binderFactory = new ServletRequestDataBinderFactory(null, initializer);
	this.mavContainer = new ModelAndViewContainer();

	this.request = new MockHttpServletRequest();
	this.webRequest = new ServletWebRequest(request);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:21,代码来源:ServletModelAttributeMethodProcessorTests.java

示例7: requestMappingHandlerAdapter

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
@Test
public void requestMappingHandlerAdapter() throws Exception {

	delegatingConfig.setConfigurers(Arrays.asList(webMvcConfigurer));
	RequestMappingHandlerAdapter adapter = delegatingConfig.requestMappingHandlerAdapter();

	ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
	ConversionService initializerConversionService = initializer.getConversionService();
	assertTrue(initializer.getValidator() instanceof LocalValidatorFactoryBean);

	verify(webMvcConfigurer).configureMessageConverters(converters.capture());
	verify(webMvcConfigurer).configureContentNegotiation(contentNegotiationConfigurer.capture());
	verify(webMvcConfigurer).addFormatters(conversionService.capture());
	verify(webMvcConfigurer).addArgumentResolvers(resolvers.capture());
	verify(webMvcConfigurer).addReturnValueHandlers(handlers.capture());
	verify(webMvcConfigurer).configureAsyncSupport(asyncConfigurer.capture());

	assertSame(conversionService.getValue(), initializerConversionService);
	assertEquals(0, resolvers.getValue().size());
	assertEquals(0, handlers.getValue().size());
	assertEquals(converters.getValue(), adapter.getMessageConverters());
	assertNotNull(asyncConfigurer);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:24,代码来源:DelegatingWebMvcConfigurationTests.java

示例8: resolveOptional

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
@Test
@SuppressWarnings("rawtypes")
public void resolveOptional() throws Exception {
	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(new DefaultConversionService());
	WebDataBinderFactory binderFactory = new DefaultDataBinderFactory(initializer);

	Object result = resolver.resolveArgument(paramOptional, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertEquals(Optional.empty(), result);

	this.request.addParameter("name", "123");
	result = resolver.resolveArgument(paramOptional, null, webRequest, binderFactory);
	assertEquals(Optional.class, result.getClass());
	assertEquals(123, ((Optional) result).get());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:RequestParamMethodArgumentResolverTests.java

示例9: setup

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
@Before
public void setup() throws Exception {
	ConfigurableWebBindingInitializer bindingInitializer = new ConfigurableWebBindingInitializer();
	bindingInitializer.setValidator(new StubValidator());

	List<HandlerMethodArgumentResolver> customResolvers = new ArrayList<HandlerMethodArgumentResolver>();
	customResolvers.add(new ServletWebArgumentResolverAdapter(new ColorArgumentResolver()));

	GenericWebApplicationContext context = new GenericWebApplicationContext();
	context.refresh();

	handlerAdapter = new RequestMappingHandlerAdapter();
	handlerAdapter.setWebBindingInitializer(bindingInitializer);
	handlerAdapter.setCustomArgumentResolvers(customResolvers);
	handlerAdapter.setApplicationContext(context);
	handlerAdapter.setBeanFactory(context.getBeanFactory());
	handlerAdapter.afterPropertiesSet();

	request = new MockHttpServletRequest();
	response = new MockHttpServletResponse();

	// Expose request to the current thread (for SpEL expressions)
	RequestContextHolder.setRequestAttributes(new ServletWebRequest(request));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:25,代码来源:RequestMappingHandlerAdapterIntegrationTests.java

示例10: setUp

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
	this.processor = new ServletModelAttributeMethodProcessor(false);

	Method method = getClass().getDeclaredMethod("modelAttribute",
			TestBean.class, TestBeanWithoutStringConstructor.class);

	this.testBeanModelAttr = new MethodParameter(method, 0);
	this.testBeanWithoutStringConstructorModelAttr = new MethodParameter(method, 1);

	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(new DefaultConversionService());

	this.binderFactory = new ServletRequestDataBinderFactory(null, initializer );
	this.mavContainer = new ModelAndViewContainer();

	this.request = new MockHttpServletRequest();
	this.webRequest = new ServletWebRequest(request);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:20,代码来源:SerlvetModelAttributeMethodProcessorTests.java

示例11: requestMappingHandlerAdapter

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
@Test
public void requestMappingHandlerAdapter() throws Exception {
	RequestMappingHandlerAdapter adapter = mvcConfiguration.requestMappingHandlerAdapter();

	List<HttpMessageConverter<?>> expectedConverters = new ArrayList<HttpMessageConverter<?>>();
	mvcConfiguration.addDefaultHttpMessageConverters(expectedConverters);
	assertEquals(expectedConverters.size(), adapter.getMessageConverters().size());

	ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) adapter.getWebBindingInitializer();
	assertNotNull(initializer);

	ConversionService conversionService = initializer.getConversionService();
	assertNotNull(conversionService);
	assertTrue(conversionService instanceof FormattingConversionService);

	Validator validator = initializer.getValidator();
	assertNotNull(validator);
	assertTrue(validator instanceof LocalValidatorFactoryBean);
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:20,代码来源:WebMvcConfigurationSupportTests.java

示例12: provide

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <T> T provide(Method method, int parameterIndex) {
	MethodParameter methodParameter = new MethodParameter(method, parameterIndex);
	ModelAndViewContainer modelAndViewContainer = new ModelAndViewContainer();
	NativeWebRequest webRequest = new ServletWebRequest(request);
	DefaultDataBinderFactory binderFactory = new DefaultDataBinderFactory(new ConfigurableWebBindingInitializer());

	try {
		return (T) argumentResolvers.resolveArgument(methodParameter, modelAndViewContainer, webRequest, binderFactory);
	} catch (Exception e) {
		throw new IllegalStateException(e);
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:15,代码来源:SpringParameterProvider.java

示例13: initEditableValidation

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
/**
 * 增加字符串转日期的功能
 */
@PostConstruct
public void initEditableValidation() {
    ConfigurableWebBindingInitializer initializer = (ConfigurableWebBindingInitializer) handlerAdapter.getWebBindingInitializer();
    if (initializer.getConversionService() != null) {
        GenericConversionService genericConversionService = (GenericConversionService) initializer.getConversionService();
        genericConversionService.addConverter(new StringToDateConverter());
        genericConversionService.addConverter(new StringToSQLDateConverter());
    }

}
 
开发者ID:egzosn,项目名称:spring-jdbc-orm,代码行数:14,代码来源:WebConfigBeans.java

示例14: getConfigurableWebBindingInitializer

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
/**
 * Return the {@link ConfigurableWebBindingInitializer} to use for
 * initializing all {@link WebDataBinder} instances.
 */
protected ConfigurableWebBindingInitializer getConfigurableWebBindingInitializer() {
	ConfigurableWebBindingInitializer initializer = new ConfigurableWebBindingInitializer();
	initializer.setConversionService(mvcConversionService());
	initializer.setValidator(mvcValidator());
	initializer.setMessageCodesResolver(getMessageCodesResolver());
	return initializer;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:12,代码来源:WebMvcConfigurationSupport.java

示例15: setUp

import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; //导入依赖的package包/类
@Before
public void setUp() {
	ConfigurableWebBindingInitializer binder = new ConfigurableWebBindingInitializer();
	GenericConversionService service = new DefaultConversionService();
	service.addConverter(new Converter<String, NestedBean>() {
		@Override
		public NestedBean convert(String source) {
			return new NestedBean(source);
		}
	});
	binder.setConversionService(service);
	adapter.setWebBindingInitializer(binder);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:Spr7839Tests.java


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