Caused by: java.lang.IllegalStateException: Could not retrieve file for class path resource [facts/dictionary.yaml]: class path resource [facts/dictionary.yaml] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/opt/facts-controller/tmobile-facts-controller.jar!/BOOT-INF/classes!/facts/dictionary.yaml
at org.springframework.boot.convert.StringToFileConverter.getFile(StringToFileConverter.java:59) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.convert.StringToFileConverter.convert(StringToFileConverter.java:49) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.convert.StringToFileConverter.convert(StringToFileConverter.java:34) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.core.convert.support.GenericConversionService$ConverterAdapter.convert(GenericConversionService.java:385) ~[spring-core-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:41) ~[spring-core-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.core.convert.support.GenericConversionService.convert(GenericConversionService.java:191) ~[spring-core-5.2.1.RELEASE.jar!/:5.2.1.RELEASE]
at org.springframework.boot.context.properties.bind.BindConverter$CompositeConversionService.convert(BindConverter.java:170) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.context.properties.bind.BindConverter.convert(BindConverter.java:96) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.context.properties.bind.BindConverter.convert(BindConverter.java:88) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.context.properties.bind.Binder.bindProperty(Binder.java:408) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.context.properties.bind.Binder.bindObject(Binder.java:353) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
at org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:293) ~[spring-boot-2.2.0.RELEASE.jar!/:2.2.0.RELEASE]
... 182 more
[ERROR] 2020-04-08 06:19:49.586 [main] LoggingFailureAnalysisReporter -
***************************
APPLICATION FAILED TO START
***************************
Description:
Failed to bind properties under 'factsgather.dictionary-path' to java.io.File:
Property: factsgather.dictionarypath
Value: /facts/dictionary.yaml
Origin: class path resource [application-gatherprops.yaml]:4:19
Reason: failed to convert java.lang.String to @javax.validation.constraints.NotNull java.io.File
Comment From: htiwari2
Can someone help me to get fix this issue . change Spring Boot version 1.x.x to 2.2.0 migration
Comment From: spencergibb
You should provide your properties files and your configuration properties java object, otherwise it will be difficult to help.
Comment From: htiwari2
ohh sorry spencergibb. Properties I have as string:
factsgather:
dictionaryPath: /facts/dictionary.yaml
and setter getter have File type - below code:
@ConfigurationProperties(prefix = "factsgather")
@Validated
public class GatherProperties {
@NotNull
private File dictionaryPath;
public File getDictionaryPath() {
return dictionaryPath;
}
public void setDictionaryPath(File dictionaryPath) {
this.dictionaryPath = dictionaryPath;
}
}
Comment From: wilkinsona
You are trying to bind /facts/dictionary.yaml
to a File
. For this to succeed the file must be available directly on the file system but /facts/dictionary.yaml
is being found nested inside your jar file. This means that it cannot be treated as a File
. You could either remove /facts/dictionary.yaml
from your jar file and make it available on the file system, or you could change how you are accessing it. For example GatherProperties.dictionaryPath
could be a URL
which would allow it to be loaded from a more flexible set of locations.
If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.
Comment From: htiwari2
locations
Thanks wilkinsona but same code working with 1.5.2.RELEASE version is there major change in 2.2.0 ? and can you please elaborate ur example. or any example u have.
Comment From: wilkinsona
Sorry, I can't say why it worked with Spring Boot 1.x as you haven't provided a complete example. Just like 2.x, 1.x cannot load a File
from inside a jar so there must be something more to it in 1.x that you haven't shown.
If you'd like us to spend some time investigating that difference, please take the time to provide a complete and minimal sample that works with 1.x and fails with 2.x. You can share such a sample with us by zipping it up and attaching it to this issue or by pushing it to a separate repository on GitHub.
You can read from a URL
by using openConnection()
and then getInputStream()
.