在Grails i18n插件defined thusly中定义了一个messageSource bean:
messageSource(PluginAwareResourceBundleMessageSource) {
basenames = baseNames.toArray()
fallbackToSystemLocale = false
pluginManager = manager
....
}
是否可以覆盖我的resources.groovy中的fallbackToSystemLocale值的配置,例如:
messageSource {
fallbackToSystemLocale = true
}
以上不起作用,我得到一个错误:“创建名为’messageSource’的bean时出错:Bean定义是抽象的”
解决方法:
有没有理由不在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)
}
原文地址:https://codeday.me/bug/20190529/1178669.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。