Announcement Announcement Module
Collapse
No announcement yet.
Roo - MessageSource issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Roo - MessageSource issue

    Hi everybody,
    I'm experiencing a very strange behavior while accessing the MessageSource form java class.

    I needed to access the MessageSource from a java class so what I did was to add a class annotated with @RooConfigurable and @RooJavaBean with an @Autowired property:
    Code:
    @RooConfigurable
    @RooJavaBean
    public class LocalizationUtils {
    
    	@Autowired(required = true)
    	private MessageSource messageSource;
    
    	public String localize(String code, Locale locale, Object[] parameters) {
    		return getMessageSource().getMessage(code, parameters, locale);
    	}
    }
    and then used it simply as follows
    Code:
    LocalizationUtils lUtils = new LocalizationUtils();
    In file webmvc-config.xml (created by Roo) there is the bean I thuoght would have been injected
    HTML Code:
    <bean
    	class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
    	id="messageSource"
    	p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application,WEB-INF/i18n/mail,WEB-INF/i18n/entities"
    	p:fallbackToSystemLocale="false" />
    (as you can see I added some localization resources)

    However, if I debug my code and watch the type of the property injected, I see that it's a
    Code:
    org.springframework.context.support.DelegatingMessageSource
    Then I changed my code to force the use of the ReloadableResourceBundleMessageSource bean as follows
    Code:
    @RooConfigurable
    @RooJavaBean
    public class LocalizationUtils {
    
    	@Autowired(required = true)
    	private ReloadableResourceBundleMessageSource messageSource;
    
    	public String localize(String code, Locale locale, Object[] parameters) {
    		return getMessageSource().getMessage(code, parameters, locale);
    	}
    }
    but in this case I got an error because the ReloadableResourceBundleMessageSource bean could not be found in context.

    Why can't I inject the ReloadableResourceBundleMessageSource bean into my class and how can I resolve?

    Thanks,
    Stefano
Working...
X