I am attempting to provide a Converter to convert a r,g,b tuple in application.yml into a Color object. The property resolution fails with: "org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.awt.Color]"
The Converter is declared like this:
@Component
public static class ColorConverter implements Converter<String, Color>{
@Override
public Color convert(String source) {
...
}
}
My environment:
Spring Boot 2.7
Application annotations;
@SpringBootApplication(scanBasePackages = {"my.packages"})
@EnableTransactionManagement(mode=AdviceMode.ASPECTJ)
@EnableSpringConfigured
The application does have a WebMvcConfigurer sub-class
What else I've tried:
- Adding @EnableConfigurationProperties to the application class. This makes no difference.
- Confirming that the converter registers during launch (I put a breakpoint on the zero arg constructor)
- Registering the converter in the WebMvcConfigurer (this doesn't make sense - the converter I need is on property resolution, not mvc calls - but I tried it anyway). This makes no difference.
Finally figured out the right google search terms.
The solution was to annotate the Convert class with @ConfigurationPropertiesBinding:
The @EnableConfigurationProperties annotation made no difference - sounds like that is included automagically by Spring Boot (ref: https://www.baeldung.com/spring-enable-config-properties )