I’m trying to creating a utility class with some static methods and properties, the problem is that these properties should be loaded from the messages.properties files, for multilingual porpouse.
I think I should use the MessageSourceAware but how to keep the methods static? I’m getting quite lost..
And more, how I can get the Locale? We’re using a SessionLocaleResolver but I think that in the jsp is automatically loaded. How can I get it in a class?
[Thanks, I’m quite new in Spring]
I’ll try to explain it a little better.
I’ve a class defined like
public MyClass {
protected static final MY_PROP = "this is a static property";
protected static String getMyProp() {
return MY_PROP;
}
}
and I would like to inject the MY_PROP from my messages.properties file, depending on the Locale, something like
public MyClass {
protected static final MY_PROP = messageSource.getMessage("my.prop", locale);
protected static String getMyProp() {
return MY_PROP;
}
}
Is this possible soomehow?
Ok, in the end I’ve implemented the MessageSourceAware, removed the static references and injected my class.
So something like:
and in my Rest service the Locale is automatically injected by Spring, thanks to the RequestMapping. I’ve injected also the entire class to avoid the static methods.
and this is working. : )