Thursday, March 18, 2010

ResourceBundle Message Implementation in Spring

Add below in context.xml

beans:bean id="msource" class="org.springframework.context.support.ResourceBundleMessageSource"
beans:property name="basename" value="classpath:mymessages.properties"


-----------------------------------

mymessages.properties
my.user.already.exist={0} already exist!
my.update={0} updated successfully!
my.delete={0} deleted successfully!


---------------------------------------------
Last step just do an autowire in the controller class

@Autowired
@Qualifier("msource")
private MessageSource mymess;

and in the functions use it like below
mymess.getMessage("my.user.already.exist", new Object[] { "Username chandra"}, null)

the Object[] can take multiple params based on the message u want to display
ex:Username {0} cannot be deleted because {1}

--- :)

No comments: