关于Spring ResourceBundleMessageSource&ApplicationContext的讨论

最近美国那边的工程师提了个问题,关于 ResourceBundleMessageSource初始化的问题,
HLD的详情是这样的,他想使用ResourceBundleMessageSource这个对象在Java code里面实现国际化,(Java code是一个Helper class,不继承任何类,用于jsp显示辅助,为让jsp干净做的),但是怎么得到ResourceBundleMessageSource这个对象呢,他给的HLD的这样的:

For access in Java: with the above bean.xml, any of the Spring ResourceBundleMessageSource methods will find and use the named bundle.  Those Spring methods can be used directly (upon Getting Locale as above) – for example:
org.springframework.context.support. * ;

String ResourceBundleMessageSource.getMessage(String key  
//  message key
                                              String[],  //  message args
                                              String,    //  default value
                                              Locale)

引用原文,

于是我就开始寻找怎么得到ResourceBundleMessageResource如何实例化,大家都知道ResourceBundleMessageResource是在国际化的时候使用的,我们通常在spring的bean.xml里面这样配置来加载我们的资源文件:

       < bean  id ="messageSource"
            class
="org.springframework.context.support.ResourceBundleMessageSource" >
            
< property  name ="basenames" >
                  
< list >
                        
< value > Messages </ value >
                  
</ list >
            
</ property >
      
</ bean >
Spring IOC会帮我们管理ResourceBundleMessageResource对象的实例话和资源文件的加载.

也就是说在我们的应用启动的时候这些文件已经被加载了,对象已经被实例化了,我们要怎么拿到这个对象,使得我们在java code里面可以使用这个对象呢?

查遍了所有的Spring source code没有发现好的方法,可以这样做么?

      ResourceBundleMessageSource ms   =   new  ResourceBundleMessageSource();           
         //
Actually, This object had been created when the bean.xml is loaded.
         //Shall I should create another?
     
// not singleton? Too many object will be created?
      ms
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值