Here is my class,
public class MyBusinessException extends RuntimeException {
@Autowired
private MessageSource messageSource;
private String errorCode;
private String messageInEnglish;
public MyBusinessException(String errorCode){
this.errorCode=errorCode;
this.messageInEnglish=messageSource.getMessage(this.code,null, Locale.ENGLISH);
}
}
This is an exception class.When I pass the errorCode as a parameter to constructor it should populate the error message,That`s what I am looking for.Infact I want to instantiate the class like this
throw new MyBusinessException("MY-ERROR-CODE");//want to initiate like this(only one argument for constructor)
How to achieve something like this?
All these I have tried so far:
- Constructor Autowiring.
- Using
@PostConstruct