Results 1 to 4 of 4

Thread: Internationalization and external resource file

  1. #1
    Join Date
    Jul 2012
    Posts
    3

    Default Internationalization and external resource file

    Hello
    I have got a big problem :/
    Standard bean for internationalization for spring is :
    PHP Code:
    <bean id="messageSource"
        
    class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <
    property name="basename" value="classpath:messages" />
        <
    property name="defaultEncoding" value="UTF-8"/>
    </
    bean
    so i shared message_en.properties in resources/messages_en.properties in my war file
    but i need to have got choice to load resource file from another external resource (example /usr/local/resouce/messages_en.properties) or if in this location i havent got file so my properties is load from default resouse in war file ??
    so i havent got any ide how to do it :/
    i think that i myst extends bean ReloadableresouceBundleMessageSource and rewrite some method
    but i havent got any idea how to do it so please help my if you can

    thx

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    No you don't... I suggest you read the reference manual especially the part about resource loading, next to that check the javadocs of the ReloadableResourceBundleMessageSource to check the properties that can help you.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Jul 2012
    Posts
    3

    Unhappy

    Hello
    I do as you say but i dont know what is wrong :

    in configuration i wrote:
    PHP Code:
    <bean id="messageSource" class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
            <
    property name="resourceLoader" >
                <
    bean class="web.servlets.controller.ResourceBundleLoader">
                </
    bean>
            </
    property>
        </
    bean
    and my ResourceBundleLoader:
    PHP Code:
    public class ResourceBundleLoader implements ResourceLoader{

        @
    Override
        
    public Resource getResource(String location) {
            
    System.out.println("location: " location);
            
            
    ApplicationContext appContext = new ClassPathXmlApplicationContext("applicationContext.xml");

            if(
    location == null)
            {
                
    System.out.println("Location == null ");
                
    location "file:/usr/local/storage/test/mainweb";
            }
            
            
    Resource resource appContext.getResource(location);
            
            if(
    resource == null)
            {
                
    System.out.println("resource == null ");
                return 
    null;
            }else{
                
    System.out.println("Resource != null");
            }
            
            return 
    resource;
        }

        @
    Override
        
    public ClassLoader getClassLoader() {
            
    // TODO Auto-generated method stub
            
    return null;
        }
        
        

    and i have got properties file in location "/usr/local/storeg/test/mainweb_en.properties"

    So what i doing wrong ?
    I hage got error in jboss:
    PHP Code:
    ERROR [org.springframework.web.servlet.tags.MessageTag] (http--127.0.0.1-8080-2No message found under code 'TITLE' for locale 'en_US'.: javax.servlet.jsp.JspTagExceptionNo message found under code 'TITLE' for locale 'en_US'.
        
    at org.springframework.web.servlet.tags.MessageTag.doStartTagInternal(MessageTag.java:184) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        
    at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:79) [spring-webmvc-3.1.1.RELEASE.jar:3.1.1.RELEASE]
        
    at org.apache.jsp.WEB_002dINF.webpages.lupaband.main.Index_jsp._jspx_meth_spring_005fmessage_005f0(Index_jsp.java:113)
        
    at org.apache.jsp.WEB_002dINF.webpages.lupaband.main.Index_jsp._jspService(Index_jsp.java:75

  4. #4
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,624

    Default

    I do as you say but i dont know what is wrong :
    No you don't... You are making it way to complex... As stated read the resource loading part of the reference guide to understand resource loading.

    Code:
    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="file:/usr/local/storage/test/mainweb" />
        <property name="defaultEncoding" value="UTF-8"/>
    </bean>
    You don't need to mess around with resource loaders just understand how the mechanism works and how the beans work!
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Tags for this Thread

Posting Permissions

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