Skip to content

PropertySourcesPlaceholderConfigurer can not ignore resource if not found [SPR-16334] #20881

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Dec 30, 2017 · 2 comments
Assignees
Labels
type: regression A bug that is also a regression
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 30, 2017

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:

Referenced from: commits 1a154c3

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

Our resource abstraction consistently throws FileNotFoundException even for NIO access now, following its original javadoc contract. This makes existing catch (FileNotFoundException) clauses work as before.

@spring-projects-issues
Copy link
Collaborator Author

Attila Turcsan commented

Our team are glad that you find a solution for this. Thank you for the fast respond and of course for your hard work on this awesome framework.
Keep up with the good work =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

2 participants