BMH*_*BMH 1 grails spring internationalization
我需要messageSource上课src\groovy.这个类用于UrlMappings.groovy,在我使用这个类的阶段,应用程序尚未完全启动.
目前我正在使用以下功能:
MessageSource messageSource = ApplicationHolder.application.mainContext.getBean('messageSource')
String message = messageSource.getMessage("code", null, "default", locale)
Run Code Online (Sandbox Code Playgroud)
但是ApplicationHolder已经弃用了,有没有办法在不使用的情况下实现相同的目标ApplicationHolder?
//我正在使用Grails 2.0.1
根据我有限的经验,我发现获得messageSourcePOGO 的最简单方法就是:
Holders.applicationContext.getBean("messageSource")
Run Code Online (Sandbox Code Playgroud)
我尝试的其他方法(实现MessageSourceAware或添加@Component/ @Autowired注释)引起了其他并发症.
| 归档时间: |
|
| 查看次数: |
5192 次 |
| 最近记录: |