Annotation Type EnableI18N
To be used together with @Configuration
classes as
follows, configuring current thread context class loader's I18N context
provider using the provided I18N configuration file, if any
(see I18nConfiguration
):
@Configuration @EnableI18N public class AppConfig { }
To provide a custom configuration (ignoring the any configuration file if
desired) implement I18nSpringConfigurer
in the
@Configuration
class:
@Configuration @EnableI18N public class AppConfig implements I18nSpringConfigurer { @Override public void configureI18nContextProvider( @NotNull I18nSpringContextProvider.Builder builder, @NotNull ApplicationContext context) { // Custom provider configuration } }
This allows using custom I18nSpringContextProvider
extensions:
@Configuration @EnableI18N public class AppConfig implements I18nSpringConfigurer { @Override public @NotNull I18nSpringContextProvider.Builder getI18nContextProviderBuilder() { return MyCustomSpringContextProvider.builder(); } @Override public void configureI18nContextProvider( @NotNull I18nSpringContextProvider.Builder builder, @NotNull ApplicationContext context) { MyCustomSpringContextProvider.Builder myBuilder = (MyCustomSpringContextProvider.Builder) builder; // Custom provider configuration } }
By default current current thread context class loader's I18N context
provider is configured.
In J2EE contexts loading Spring context through
ContextLoaderListener
this means the WAR's class loader.
To configure an EAR class loader's I18N context provider (for example
in shared parent contexts loaded through
ContextLoaderListener.loadParentContext(ServletContext)
),
set a class in the EAR's libraries (the @Configuration
class, for example):
@Configuration @EnableI18N(classLoader=SharedAppConfig.class) public class SharedAppConfig { }
This allows separate I18N configurations for EAR level thread like asynchronous task executors or JMS listeners threads and WAR and EJB modules if desired.
- Since:
- 0.1
- Version:
- 1.0, 2021-01
- Author:
- (w) Iker Hernaez
- See Also:
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionClass<?>
Returns the class whomClassLoader
to apply the configuration to.
-
Element Details
-
classLoader
Class<?> classLoaderReturns the class whomClassLoader
to apply the configuration to.Default value
Void.class
configures the current thread context class loader's I18N context provider.See
EnableI18N
javadoc for additional examples.- Returns:
- The class whom
ClassLoader
to apply the configuration to.
- Default:
- java.lang.Void.class
-