<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource"
p:basename="messages" />
bean and obviously in my velocity files I can use #springMessage() to get needed message. But what if I want 开发者_高级运维to get that message in my *.java controller? Is there some annotation that I can use like ?
@Annotation('message')
private String message;
Or I need to do it in different way?
Thanks
As long as you don't need any internationalization, then you can use the messages.properties
file with a PropertyPlaceHolderConfigurer
(see the docs), along with the @Value
annotation
In XML:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:messages.properties"/>
</bean>
And in Java:
@Value('message')
private String message;
You'll also need <context:annotation-config/>
to make this work (see docs)
精彩评论