FormattingConversionService
configured with converters and formatters for common types such as numbers and
datetimes.
Additional converters and formatters can be registered declaratively through
setConverters(Set) and setFormatters(Set). Another option
is to register converters and formatters in code by implementing the
FormatterRegistrar interface. You can then configure provide the set
of registrars to use through setFormatterRegistrars(Set).
A good example for registering converters and formatters in code is
JodaTimeFormatterRegistrar, which registers a number of
date-related formatters and converters. For a more detailed list of cases
see setFormatterRegistrars(Set)
Like all FactoryBean implementations, this class is suitable for
use when configuring a Spring application context using Spring <beans>
XML. When configuring the container with
@Configuration
classes, simply instantiate, configure and return the appropriate
FormattingConversionService object from a
@Bean method.
| Modifier and Type | Field and Description |
|---|---|
| private FormattingConversionService | |
| private Set | |
| private StringValueResolver | |
| private Set | |
| private Set | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | afterPropertiesSet()
Implements org. BeanFactory after it has set all bean properties
and satisfied BeanFactoryAware, ApplicationContextAware etc.
This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set. |
| public FormattingConversionService | getObject()
Implements org. |
| public Class | getObjectType()
Implements org. null if not known in advance.
|
| public boolean | isSingleton()
Overrides default org. |
| private void | |
| public void | |
| public void | setEmbeddedValueResolver(StringValueResolver embeddedValueResolver)
Implements org. |
| public void | setFormatterRegistrars(Set<FormatterRegistrar> formatterRegistrars)
Configure the set of FormatterRegistrars to invoke to register
Converters and Formatters in addition to those added declaratively
via |
| public void | setFormatters(Set<?>
instances of formatters)Formatter or AnnotationFormatterFactoryConfigure the set of custom formatter objects that should be added. |
| public void | setRegisterDefaultFormatters(boolean registerDefaultFormatters)
Indicate whether default formatters should be registered or not. |
| conversionService | back to summary |
|---|---|
| private FormattingConversionService conversionService
| |
| converters | back to summary |
|---|---|
| private Set<?> converters
| |
| embeddedValueResolver | back to summary |
|---|---|
| private StringValueResolver embeddedValueResolver
| |
| formatterRegistrars | back to summary |
|---|---|
| private Set<FormatterRegistrar> formatterRegistrars
| |
| formatters | back to summary |
|---|---|
| private Set<?> formatters
| |
| registerDefaultFormatters | back to summary |
|---|---|
| private boolean registerDefaultFormatters | |
| FormattingConversionServiceFactoryBean | back to summary |
|---|---|
| public FormattingConversionServiceFactoryBean() | |
| afterPropertiesSet | back to summary |
|---|---|
| public void afterPropertiesSet() Implements org. Doc from org. Invoked by the containing This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.
| |
| getObject | back to summary |
|---|---|
| public FormattingConversionService getObject() Implements org. Doc from org. Return an instance (possibly shared or independent) of the object managed by this factory. As with a If this FactoryBean is not fully initialized yet at the time of
the call (for example because it is involved in a circular reference),
throw a corresponding As of Spring 2.0, FactoryBeans are allowed to return
| |
| getObjectType | back to summary |
|---|---|
| public Class Implements org. Doc from org. Return the type of object that this FactoryBean creates,
or This allows one to check for specific types of beans without instantiating objects, for example on autowiring. In the case of implementations that are creating a singleton object, this method should try to avoid singleton creation as far as possible; it should rather estimate the type in advance. For prototypes, returning a meaningful type here is advisable too. This method can be called before this FactoryBean has been fully initialized. It must not rely on state created during initialization; of course, it can still use such state if available. Note Autowiring will simply ignore FactoryBeans that return
| |
| isSingleton | back to summary |
|---|---|
| public boolean isSingleton() Overrides default org. Doc from org. Is the object managed by this factory a singleton? That is,
will Note If a FactoryBean indicates to hold a singleton object,
the object returned from The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there. Note This method returning The default implementation returns
| |
| registerFormatters | back to summary |
|---|---|
| private void registerFormatters(FormattingConversionService conversionService) | |
| setConverters | back to summary |
|---|---|
| public void setConverters(Set<?> converters) Configure the set of custom converter objects that should be added.
| |
| setEmbeddedValueResolver | back to summary |
|---|---|
| public void setEmbeddedValueResolver(StringValueResolver embeddedValueResolver) Implements org. Doc from org. Set the StringValueResolver to use for resolving embedded definition values.
| |
| setFormatterRegistrars | back to summary |
|---|---|
| public void setFormatterRegistrars(Set<FormatterRegistrar> formatterRegistrars) Configure the set of FormatterRegistrars to invoke to register
Converters and Formatters in addition to those added declaratively
via FormatterRegistrars are useful when registering multiple related converters and formatters for a formatting category, such as Date formatting. All types related needed to support the formatting category can be registered from one place. FormatterRegistrars can also be used to register Formatters indexed under a specific field type different from its own <T>, or when registering a Formatter from a Printer/Parser pair. | |
| setFormatters | back to summary |
|---|---|
| public void setFormatters(Set<?> formatters) Configure the set of custom formatter objects that should be added.
| |
| setRegisterDefaultFormatters | back to summary |
|---|---|
| public void setRegisterDefaultFormatters(boolean registerDefaultFormatters) Indicate whether default formatters should be registered or not. By default, built-in formatters are registered. This flag can be used to turn that off and rely on explicitly registered formatters only. | |