Closed
Description
Attila Turcsan opened SPR-16334 and commented
Possible bug is the PSPConfigurer not catching the right exception when the setIgnoreResourceNotFound option is true.
I got java.nio.file.NoSuchFileException but it only catches java.io.FIleNotFoundException.
Running environment:
Java: jdk1.8.0_144
Kotlin: 1.2.10
Running with Spring Boot v2.0.0.M7, Spring v5.0.2.RELEASE
@Bean
open fun propertyPlaceholderConfigurer(): PropertySourcesPlaceholderConfigurer {
return PropertySourcesPlaceholderConfigurer().apply {
setIgnoreResourceNotFound(true)
order = Ordered.HIGHEST_PRECEDENCE
setLocations(
ClassPathResource("default.properties"),
FileSystemResource("${user.home}/desktop.properties")
)
}
}
This is the exception stack:
org.springframework.beans.factory.BeanInitializationException: Could not load properties; nested exception is java.nio.file.NoSuchFileException: /Users/dev/desktop.properties
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:153)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:284)
at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:164)
at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:693)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:531)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:138)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:751)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:387)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:136)
at hu.hobbesmedia.legenda.cassa.BootstrapKt.main(Bootstrap.kt:79)
Caused by: java.nio.file.NoSuchFileException: /Users/dev/desktop.properties
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixFileSystemProvider.newByteChannel(UnixFileSystemProvider.java:214)
at java.nio.file.Files.newByteChannel(Files.java:361)
at java.nio.file.Files.newByteChannel(Files.java:407)
at java.nio.file.spi.FileSystemProvider.newInputStream(FileSystemProvider.java:384)
at java.nio.file.Files.newInputStream(Files.java:152)
at org.springframework.core.io.FileSystemResource.getInputStream(FileSystemResource.java:123)
at org.springframework.core.io.support.EncodedResource.getInputStream(EncodedResource.java:159)
at org.springframework.core.io.support.PropertiesLoaderUtils.fillProperties(PropertiesLoaderUtils.java:99)
at org.springframework.core.io.support.PropertiesLoaderSupport.loadProperties(PropertiesLoaderSupport.java:181)
at org.springframework.core.io.support.PropertiesLoaderSupport.mergeProperties(PropertiesLoaderSupport.java:162)
at org.springframework.context.support.PropertySourcesPlaceholderConfigurer.postProcessBeanFactory(PropertySourcesPlaceholderConfigurer.java:144)
Affects: 5.0.2
Issue Links:
- Unnecessary file system access in SimpleMetadataReaderFactory.getMetadataReader [SPR-16281] #20828 Unnecessary file system access in SimpleMetadataReaderFactory.getMetadataReader
- Revise FileSystemResource / FileSystemUtils / FileCopyUtils towards NIO.2 [SPR-15748] #20304 Revise FileSystemResource / FileSystemUtils / FileCopyUtils towards NIO.2
- HTTP 404 for static resources with last modified = 0L (breaks Docker images build with Jib) [SPR-17320] #21853 HTTP 404 for static resources with last modified = 0L (breaks Docker images build with Jib)
Referenced from: commits 1a154c3