Results 1 to 3 of 3

Thread: how to get MessageResource via programing API?

  1. #1
    Join Date
    Dec 2006
    Posts
    11

    Default how to get MessageResource via programing API?

    sorry for such an ignorance question.

    how can i get message source from programming API, not via DI.
    i did the following but failed. the log is not able to show "myapp". pls help.

    ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicati onContext(servletContext);
    String message = ctx.getMessage("webapp.name", null, null);
    log.debug("my web app name:" + message);

    ------
    /WEB-INF/ApplicationResource.properties
    ------
    webapp.name=myapp

  2. #2
    Join Date
    Nov 2006
    Location
    Germany
    Posts
    452

    Default

    Hi,

    you have to setup your messageSourceBean

    http://static.springframework.org/sp...-messagesource

    Then you should see your message, even if you are getting the MessageSource programatically (like in the reference docs)

    regards
    lyserg

  3. #3
    Join Date
    Mar 2006
    Location
    Bangalore, India
    Posts
    242

    Smile

    Hi ,

    you would have to register the messageSource bean as follows
    Code:
    <bean id="messageSource"  class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
            <property name="basenames">
                <list>
                    <value>/WEB-INF/ApplicationResource.properties</value>
                </list>
            </property>
            <property name="cacheSeconds" value="10"/>
        </bean>
    then use the applicationContext to lookup the bean
    Code:
    MessageSource source = (MessageSource)ctx.getBean("messageSource")
    String message =source.getMessage("webapp.name",null,null);
    you could also inject the messageSource Bean into the dependent bean
    Sami

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •