You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Starting from spring-boot 2.4.4 and including spring-boot-starter-web, injection on Path objects misinterprets absolute paths which are transformed into relative paths.
@ComponentpublicclassPathInjectionIssue {
@Value("${myconfigfile}")
privatePathconfigAsPath; // here is the issue@Value("${myconfigfile}")
privateFileconfigAsFile; /// this one is OK@Value("${myconfigfile}")
privateStringconfigFileAsString; // this one is OK this is just a string@PostConstructpublicvoidcheck() {
if (configAsPath.getNameCount() > 1) {
thrownewRuntimeException("This absolute file path [" + configAsPath.toAbsolutePath() + "] is not correct. Expected : " + configFileAsString);
}
}
}
This application.properties file :
myconfigfile=/conf.json
The output is :
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'pathInjectionIssue': Invocation of init method failed; nested exception is java.lang.RuntimeException: This absolute file path [C:\Users\shelbert\AppData\Local\Temp\tomcat-docbase.8080.9485259209731591160\conf.json] is not correct. Expected : /conf.json
[...]
There is no issue with spring-boot 2.4.3 nor without the spring-boot-starter-web dependency
The text was updated successfully, but these errors were encountered:
Came to say that I am experiencing the same. In my case, I have a Path property defined inside a @ConfigurationProperties bean and we set it using command line using the below syntax:
Starting from spring-boot 2.4.4 and including spring-boot-starter-web, injection on Path objects misinterprets absolute paths which are transformed into relative paths.
For exemple with this pom file :
And This Component :
This application.properties file :
The output is :
There is no issue with spring-boot 2.4.3 nor without the spring-boot-starter-web dependency
The text was updated successfully, but these errors were encountered: