I have the Enum
:
public enum EmployeeErrorCode {
DELETE_SUCCESS,
//... Other enumerators
@Override
public String toString(){
ApplicationContext ctx = ContextLoader
.getCurrentWebApplicationContext();
MessageSource messageSource = (MessageSource) ctx
.getBean("messageSource"); //How to avoid this?
switch (this) {
case DELETE_SUCCESS:
return messageSource.getMessage("deleteEmployee.success",
null, LocaleContextHolder.getLocale());
//... Other cases
default:
return null;
}
}
}
In the toString
nethod I specified the messages for any Enumerator
, but I used getBean
method to programmatically get the appropriate bean. How can I avoid that?
I tried to inject the bean via
@Autowired
MessageSource messageSource;
but it didn't work. In fact, messageSource was just null
. Is there a way to do that corretly at all?