本文整理汇总了Java中org.springframework.core.convert.support.DefaultConversionService类的典型用法代码示例。如果您正苦于以下问题:Java DefaultConversionService类的具体用法?Java DefaultConversionService怎么用?Java DefaultConversionService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultConversionService类属于org.springframework.core.convert.support包,在下文中一共展示了DefaultConversionService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMangoConfig
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
public static MangoConfig getMangoConfig(DefaultListableBeanFactory beanFactory,String prefix){
MangoConfig target = new MangoConfig();
PropertiesConfigurationFactory<Object> factory = new PropertiesConfigurationFactory<Object>(target);
factory.setPropertySources(deducePropertySources(beanFactory));
factory.setConversionService(new DefaultConversionService());
factory.setIgnoreInvalidFields(false);
factory.setIgnoreUnknownFields(true);
factory.setIgnoreNestedProperties(false);
factory.setTargetName(prefix);
try {
factory.bindPropertiesToTarget();
}
catch (Exception ex) {
throw new MangoAutoConfigException(ex);
}
return target;
}
示例2: setup
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
@Before
public void setup() throws Exception {
@SuppressWarnings("resource")
GenericApplicationContext cxt = new GenericApplicationContext();
cxt.refresh();
this.resolver = new HeaderMethodArgumentResolver(new DefaultConversionService(), cxt.getBeanFactory());
Method method = getClass().getDeclaredMethod("handleMessage",
String.class, String.class, String.class, String.class, String.class);
this.paramRequired = new SynthesizingMethodParameter(method, 0);
this.paramNamedDefaultValueStringHeader = new SynthesizingMethodParameter(method, 1);
this.paramSystemProperty = new SynthesizingMethodParameter(method, 2);
this.paramNotAnnotated = new SynthesizingMethodParameter(method, 3);
this.paramNativeHeader = new SynthesizingMethodParameter(method, 4);
this.paramRequired.initParameterNameDiscovery(new DefaultParameterNameDiscoverer());
GenericTypeResolver.resolveParameterType(this.paramRequired, HeaderMethodArgumentResolver.class);
}
示例3: testBindingErrorWithFormatter
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
@Test
public void testBindingErrorWithFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
binder.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1x2");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertEquals(new Float(0.0), tb.getMyFloat());
assertEquals("1x2", binder.getBindingResult().getFieldValue("myFloat"));
assertTrue(binder.getBindingResult().hasFieldErrors("myFloat"));
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例4: testBindingWithFormatterAgainstList
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
@Test
public void testBindingWithFormatterAgainstList() {
BeanWithIntegerList tb = new BeanWithIntegerList();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
binder.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("integerList[0]", "1");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertEquals(new Integer(1), tb.getIntegerList().get(0));
assertEquals("1", binder.getBindingResult().getFieldValue("integerList[0]"));
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例5: testBindingErrorWithFormatterAgainstList
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
@Test
public void testBindingErrorWithFormatterAgainstList() {
BeanWithIntegerList tb = new BeanWithIntegerList();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
binder.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("integerList[0]", "1x2");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertTrue(tb.getIntegerList().isEmpty());
assertEquals("1x2", binder.getBindingResult().getFieldValue("integerList[0]"));
assertTrue(binder.getBindingResult().hasFieldErrors("integerList[0]"));
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例6: testBindingErrorWithFormatterAgainstFields
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
@Test
public void testBindingErrorWithFormatterAgainstFields() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
binder.initDirectFieldAccess();
FormattingConversionService conversionService = new FormattingConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
binder.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1x2");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertEquals(new Float(0.0), tb.getMyFloat());
assertEquals("1x2", binder.getBindingResult().getFieldValue("myFloat"));
assertTrue(binder.getBindingResult().hasFieldErrors("myFloat"));
}
finally {
LocaleContextHolder.resetLocaleContext();
}
}
示例7: setUp
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
@Before
public void setUp() {
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.setEmbeddedValueResolver(new StringValueResolver() {
@Override
public String resolveStringValue(String strVal) {
if ("${pattern}".equals(strVal)) {
return "#,##.00";
}
else {
return strVal;
}
}
});
conversionService.addFormatterForFieldType(Number.class, new NumberStyleFormatter());
conversionService.addFormatterForFieldAnnotation(new NumberFormatAnnotationFormatterFactory());
LocaleContextHolder.setLocale(Locale.US);
binder = new DataBinder(new TestBean());
binder.setConversionService(conversionService);
}
示例8: test
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的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);
}
示例9: setUp
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的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
示例10: resolveOptional
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的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
示例11: testCustomConverter
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
@Test
public void testCustomConverter() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
GenericConversionService conversionService = new DefaultConversionService();
conversionService.addConverter(new Converter<String, Float>() {
@Override
public Float convert(String source) {
try {
NumberFormat nf = NumberFormat.getInstance(Locale.GERMAN);
return nf.parse(source).floatValue();
}
catch (ParseException ex) {
throw new IllegalArgumentException(ex);
}
}
});
lbf.setConversionService(conversionService);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1,1");
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("testBean", bd);
TestBean testBean = (TestBean) lbf.getBean("testBean");
assertTrue(testBean.getMyFloat().floatValue() == 1.1f);
}
示例12: MappingRedisConverter
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
public MappingRedisConverter(IndexConfiguration indexConfiguration, ReferenceResolver referenceResolver) {
mappingContext = new KeyValueMappingContext();
entityInstantiators = new EntityInstantiators();
this.conversionService = new DefaultConversionService();
this.conversionService.addConverter(new BinaryConverters.StringToBytesConverter());
this.conversionService.addConverter(new BinaryConverters.BytesToStringConverter());
this.conversionService.addConverter(new BinaryConverters.NumberToBytesConverter());
this.conversionService.addConverterFactory(new BinaryConverters.BytesToNumberConverterFactory());
this.conversionService.addConverter(new BinaryConverters.EnumToBytesConverter());
this.conversionService.addConverterFactory(new BinaryConverters.BytesToEnumConverterFactory());
this.conversionService.addConverter(new BinaryConverters.BooleanToBytesConverter());
this.conversionService.addConverter(new BinaryConverters.BytesToBooleanConverter());
this.conversionService.addConverter(new BinaryConverters.DateToBytesConverter());
this.conversionService.addConverter(new BinaryConverters.BytesToDateConverter());
typeMapper = new DefaultTypeMapper<RedisData>(new RedisTypeAliasAccessor(this.conversionService));
this.indexConfiguration = indexConfiguration != null ? indexConfiguration : new IndexConfiguration();
this.referenceResolver = referenceResolver;
}
示例13: testBindingSsh
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
@Test
public void testBindingSsh() {
ShellProperties props = new ShellProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell");
binder.setConversionService(new DefaultConversionService());
Map<String, String> map = new HashMap<String, String>();
map.put("shell.ssh.enabled", "true");
map.put("shell.ssh.port", "2222");
map.put("shell.ssh.key_path", "~/.ssh/test.pem");
binder.bind(new MutablePropertyValues(map));
assertFalse(binder.getBindingResult().hasErrors());
Properties p = props.asCrshShellConfig();
assertEquals("2222", p.get("crash.ssh.port"));
assertEquals("~/.ssh/test.pem", p.get("crash.ssh.keypath"));
}
示例14: testBindingSshIgnored
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
@Test
public void testBindingSshIgnored() {
ShellProperties props = new ShellProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell");
binder.setConversionService(new DefaultConversionService());
Map<String, String> map = new HashMap<String, String>();
map.put("shell.ssh.enabled", "false");
map.put("shell.ssh.port", "2222");
map.put("shell.ssh.key_path", "~/.ssh/test.pem");
binder.bind(new MutablePropertyValues(map));
assertFalse(binder.getBindingResult().hasErrors());
Properties p = props.asCrshShellConfig();
assertNull(p.get("crash.ssh.port"));
assertNull(p.get("crash.ssh.keypath"));
}
示例15: testBindingSimple
import org.springframework.core.convert.support.DefaultConversionService; //导入依赖的package包/类
@Test
public void testBindingSimple() {
SimpleAuthenticationProperties props = new SimpleAuthenticationProperties();
RelaxedDataBinder binder = new RelaxedDataBinder(props, "shell.auth.simple");
binder.setConversionService(new DefaultConversionService());
Map<String, String> map = new HashMap<String, String>();
map.put("shell.auth.simple.user.name", "username123");
map.put("shell.auth.simple.user.password", "password123");
binder.bind(new MutablePropertyValues(map));
assertFalse(binder.getBindingResult().hasErrors());
Properties p = new Properties();
props.applyToCrshShellConfig(p);
assertEquals("username123", p.get("crash.auth.simple.username"));
assertEquals("password123", p.get("crash.auth.simple.password"));
}