Results 1 to 2 of 2

Thread: Problem with ReloadableResourceBundleMessageSource

  1. #1
    Join Date
    Dec 2012
    Posts
    1

    Unhappy Problem with ReloadableResourceBundleMessageSource

    Hi everyone !

    i have a problem using the class ReloadableResourceBundleMessageSource...
    i'll explain my problem. I want to use Messages on server Side, and i' trying to use ReloadableResourceBundleMessageSource.

    i have define this in my Spring file :
    Code:
     <bean id="messageSource"
              class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
            <property name="basenames">
                <list>
                      <value>WEB-INF/content/SoftCuStrings</value>
                </list>
            </property>
            <property name="defaultEncoding" value="UTF-8"/>
        </bean>
    and SoftCuStrings is my *.properties file

    i have created a Listener :
    Code:
    public class CmiServletListener implements ServletContextListener {
    	@Override
    	public void contextInitialized(ServletContextEvent sce) {
    		ServerMessageResourceFactory serverMessageResourceFactory = (ServerMessageResourceFactory) WebApplicationContextUtils
    				.getWebApplicationContext(sce.getServletContext()).getBean("serverMessageResourceFactory");
    		SoftCuMessageTest.SERVER_GLOBAL_RES = serverMessageResourceFactory.getSoftCuStrings();
    	}
    
    	@Override
    	public void contextDestroyed(ServletContextEvent sce) {
    
    	}
    }
    which is defined in my web.xml :
    Code:
       <listener>
            <listener-class>com.francetelecom.softcu.app.impl.listener.CmiServletListener</listener-class>
       </listener>
    the bean in this code is define in my spring file :
    Code:
    <bean id="serverMessageResourceFactory" class="com.francetelecom.softcu.app.impl.listener.ServerMessageResourceFactory"/>
    and here is my serverMessageResourceFactory file :
    Code:
    public class ServerMessageResourceFactory {
    
    	InvocationHandler handler = new InvocationHandler() {
    		@Override
    		public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    			return messageSource.getMessage(method.getAnnotation(LocalizableResource.Key.class).value(), args, null);
    		}
    	};
    	private ReloadableResourceBundleMessageSource messageSource;
    
    	public SoftCuStrings getSoftCuStrings() {
    		return (SoftCuStrings) Proxy.newProxyInstance(SoftCuStrings.class.getClassLoader(), new Class[] { SoftCuStrings.class }, handler);
    	}
    
    	public void setMessageResource(ReloadableResourceBundleMessageSource messageSource) {
    		this.messageSource = messageSource;
    	}
    }
    to be quick, when i'm using my serverMessageResourceFactory, my messageResource is null...
    i thought that my classpath is wrong, but, i don't think so...
    someone can help me ? beacause i'm completely stuck :/

    thx !!

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

    Default

    to be quick, when i'm using my serverMessageResourceFactory, my messageResource is null...
    And why should it be injected?! You no where specify it to be injected. There is no annotation on the field nor do you define the property in your xml file. So how on earth should spring know you want that injected?

    Also your code is flawed use the MessageSource interface instead of the concrete implementation to program against! I would suggest you let your ServerMessageResourceFactory implement MessageSourceAware...
    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

Posting Permissions

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