Reputation: 1693
I'm trying to figure out how to make the ProblemDetailsExceptionHandler work properly and return some details from the validationResults. Because the default MessageSource being used is the DelegatingMessageSource it delegates to the parentMessagSource, but I'm not having anything injected there. Even if I created a ResourceBundleMessageSource as parentMessageSource.
I've tried to add the following app configuration:
@Bean
@Qualifier("parentMessageSource")
public MessageSource parentMessageSource() {
ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasename(MESSAGES_BASENAME);
messageSource.setDefaultEncoding(UTF_8.displayName());
messageSource.setDefaultLocale(Locale.ENGLISH);
return messageSource;
}
@Bean
public LocalValidatorFactoryBean validator(MessageSource messageSource) {
LocalValidatorFactoryBean bean = new LocalValidatorFactoryBean();
bean.setValidationMessageSource(messageSource);
return bean;
}
The method I'm fighting with is this one from DelegatingMessageSource.
@Nullable
public String getMessage(String code, @Nullable Object[] args, @Nullable String defaultMessage, Locale locale) {
if (this.parentMessageSource != null) {
return this.parentMessageSource.getMessage(code, args, defaultMessage, locale);
} else {
return defaultMessage != null ? this.renderDefaultMessage(defaultMessage, args, locale) : null;
}
}
In the flow, I don't get anything in the defaultMessage, it's set to null in ErrorResonse
default ProblemDetail updateAndGetBody(@Nullable MessageSource messageSource, Locale locale) {
if (messageSource != null) {
String type = messageSource.getMessage(this.getTypeMessageCode(), (Object[])null, (String)null, locale);
...
I have problemDetails enabled in properties.
I'm using JDK 21, Spring Boot 6.4. If
Upvotes: 0
Views: 23