Reputation: 200
I have a project that has the following message source configured:
@Bean
public ReloadableResourceBundleMessageSource messageSource() {
final ReloadableResourceBundleMessageSource source = new ReloadableResourceBundleMessageSource();
source.setBasename("i18n/core/messages");
source.setDefaultEncoding("UTF-8");
source.setUseCodeAsDefaultMessage(true);
return source;
}
I want to use this "core" project as a lib for my app project. The messages are defined in this core, as resources.
In this same core project i have a @ControlerAdvice that gets all the exception that my application throws, as following:
@ExceptionHandler
public void unknownException(final Exception ex) {
if (ex instanceof StudioException){
throw (StudioException) ex;
}
final UUID uuid = UUID.randomUUID();
final String[] strings = {uuid.toString()};
String message = messageSource.getMessage("exception.not.identified",strings, LocaleContextHolder.getLocale());
final UnknownError unknownError = new UnknownError();
unknownError.setUuid(uuid.toString());
unknownError.setLogger(ExceptionUtils.getStackTrace(ex));
unknownErrorService.save(unknownError);
throw new StudioException(message);
The problem is that when i use my core project as dependency of my app project, and an exception is thronw, the ExceptionHandler is called but the messageSource cant find the key.
I tried to set the basename with "classpath:...", i changed the directory strtucure of the resources in the core to be diferent from the app project but no success.
This is where are my i18n properties:
Does anyone knows how can i solve this, having the keys and the message logic inside my core project?
Upvotes: 1
Views: 937