Package dev.orne.i18n.spring
Class I18nSpringConfiguration
java.lang.Object
dev.orne.i18n.spring.I18nSpringConfiguration
- All Implemented Interfaces:
I18nContextProvider.Configurer,org.springframework.beans.factory.Aware,org.springframework.beans.factory.InitializingBean,org.springframework.context.annotation.ImportAware,org.springframework.context.ApplicationContextAware,org.springframework.context.MessageSourceAware
- Direct Known Subclasses:
I18nSpringWebConfiguration
@API(status=STABLE,
since="0.1")
@Configuration
public class I18nSpringConfiguration
extends Object
implements org.springframework.context.ApplicationContextAware, org.springframework.context.MessageSourceAware, org.springframework.context.annotation.ImportAware, org.springframework.beans.factory.InitializingBean, I18nContextProvider.Configurer
I18N context provider configuration for Spring. Configures a
I18nContextProvider (an instance of
I18nSpringContextProvider by default).
By default configures the provider for all ClassLoaders.
Supports selecting a target class that will configure
the provider for the ClassLoader of the given class and all its
children ClassLoader, allowing different configurations for each
application even when the library is deployed as a shared library or
different configurations for each sub-module when the library is deployed
at EAR level in JavaEE environments.
- Since:
- 0.1
- Version:
- 1.0, 2023-05
- Author:
- (w) Iker Hernaez
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final I18nSpringConfigurerThe default I18N context provider configuration customizer. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidSets the configuredI18nContextProviderfor the configuredClassLoader.protected @NotNull I18nSpringContextProviderCreates a newI18nSpringContextProviderbased on configured properties.protected @NotNull I18nSpringConfigurerDetermines the I18N context provider configuration customizer to apply.protected org.springframework.context.ApplicationContextReturns the Spring application context.protected org.springframework.context.MessageSourceReturns the application defaultMessageSource.protected ClassLoaderReturns theClassLoaderthis configuration will be applied to.voidsetApplicationContext(org.springframework.context.ApplicationContext applicationContext) voidsetImportMetadata(@NotNull org.springframework.core.type.AnnotationMetadata importMetadata) Inherits configuration fromEnableI18Nannotation.voidsetMessageSource(org.springframework.context.MessageSource messageSource) voidsetTarget(ClassLoader target) Sets theClassLoaderthis configuration will be applied to.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.orne.i18n.context.I18nContextProvider.Configurer
setI18nConfiguration, setI18nConfiguration, setI18nContextProvider, setI18nContextProvider
-
Field Details
-
DEFAULT_CONFIGURER
The default I18N context provider configuration customizer.
-
-
Constructor Details
-
I18nSpringConfiguration
public I18nSpringConfiguration()Creates a new instance.
-
-
Method Details
-
getApplicationContext
protected org.springframework.context.ApplicationContext getApplicationContext()Returns the Spring application context.- Returns:
- The Spring application context.
-
setApplicationContext
public void setApplicationContext(org.springframework.context.ApplicationContext applicationContext) throws org.springframework.beans.BeansException - Specified by:
setApplicationContextin interfaceorg.springframework.context.ApplicationContextAware- Throws:
org.springframework.beans.BeansException
-
getMessageSource
protected org.springframework.context.MessageSource getMessageSource()Returns the application defaultMessageSource.- Returns:
- The application default
MessageSource.
-
setMessageSource
public void setMessageSource(org.springframework.context.MessageSource messageSource) - Specified by:
setMessageSourcein interfaceorg.springframework.context.MessageSourceAware
-
getTarget
Returns theClassLoaderthis configuration will be applied to.If
nullthe configuration will be applied to current thread's context class loader.- Returns:
- The target class loader.
-
setTarget
Sets theClassLoaderthis configuration will be applied to.If
nullthe configuration will be applied to current thread's context class loader.- Parameters:
target- The target class loader.
-
setImportMetadata
public void setImportMetadata(@NotNull @NotNull org.springframework.core.type.AnnotationMetadata importMetadata) Inherits configuration fromEnableI18Nannotation.- Specified by:
setImportMetadatain interfaceorg.springframework.context.annotation.ImportAware- Parameters:
importMetadata- The import metadata- See Also:
-
determineConfigurer
Determines the I18N context provider configuration customizer to apply.- Returns:
- The I18N context provider configuration customizer.
- Throws:
IllegalStateException- If multiple instances ofI18nSpringConfigurerare present in current Spring context.
-
createContextProvider
Creates a newI18nSpringContextProviderbased on configured properties.This implementation creates an instance of
I18nSpringContextProvider.- Returns:
- The new configured
I18nSpringContextProvider
-
afterPropertiesSet
public void afterPropertiesSet()Sets the configuredI18nContextProviderfor the configuredClassLoader.- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean
-