Grails i18n插件defined thusly中定义了messageSource
bean:
messageSource(PluginAwareResourceBundleMessageSource) {
basenames = baseNames.toArray()
fallbackToSystemLocale = false
pluginManager = manager
....
}
是否可以覆盖我的resources.groovy中fallbackToSystemLocale
值的配置,例如:
messageSource {
fallbackToSystemLocale = true
}
以上不起作用,我收到一个错误:“创建名为'messageSource'的bean时出错:Bean定义是抽象的”
答案 0 :(得分:6)
有没有理由不简单地更新BootStrap.groovy
中的bean?
class BootStrap {
def def messageSource
def init = { servletContext ->
messageSource.fallbackToSystemLocale = true
}
}
如果要在运行BootStrap之前修改bean,可以使用this blog post中的BeanPostProcessor
。
的src /常规/ yourpkg / CustomBeanPostProcessor:
import org.springframework.beans.factory.config.BeanPostProcessor
class CustomBeanPostProcessor implements BeanPostProcessor{
@Override
Object postProcessBeforeInitialization(Object bean, String beanName) {
return bean
}
@Override
Object postProcessAfterInitialization(Object bean, String beanName) {
if(beanName == 'messageSource') {
bean.setFallbackToSystemLocale = true
}
return bean
}
}
resources.groovy:
beans = {
customBeanPostProcessor(CustomBeanPostProcessor)
}