Describe the bug I am getting the following error when I build my Spring Boot application:
Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled.
2023-09-02T12:34:26.525+05:30 ERROR 1128677 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'rsa.public-key' to java.security.interfaces.RSAPublicKey:
Property: rsa.public-key
Value: "classpath:public.pem"
Origin: class path resource [application.properties] - 1:17
Reason: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [java.security.interfaces.RSAPublicKey]
Action:
Update your application's configuration
Versions - Java: 17.0.7 - Spring Boot: 3.1.3 - Spring: 6.0.11
To Reproduce
- Clone the repository: https://github.com/ContractSPAN/ConverterIssue
- Execute mvn clean install
Expected behavior As mentioned in the description of ResourceKeyConverterAdapter , "By default, keys can be read from the file system, the classpath, and from HTTP endpoints.". However, it can be observed that no converter is found.
Sample GitHub repository to reproduce issue: https://github.com/ContractSPAN/ConverterIssue
Comment From: kse-music
The addition of ResourceKeyConverterAdapterrequires a web environment. You need to add webdependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
or webfluxdependencies
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
Comment From: jzheaux
Good catch, @kse-music! @shivammalviya71234, if you aren't using web (and thus not @EnableWebSecurity) you can also wire the converters manually like so:
@Bean
public static BeanFactoryPostProcessor conversionServicePostProcessor() {
return new RsaKeyConversionServicePostProcessor();
}
I'm going to close this as answered; however, please feel free to post more information as needed.