Are properties read by Spring Property Placeholder available?

I am modifying the code that uses the Spring PropertyPlaceholderConfigurer in the application context file. Properties are successfully read and used in the application. However, if I follow the declaration of PropertyPlaceholderConfigurer with <import resource="classpath:/my/class/path/${my.file.name}" /> , the error " Could not resolve placeholder 'my.file.name' " is issued series of exceptions. Are properties available immediately after declaring a PropertyPlaceholderConfigurer? If not, at what point do they become available?

+2
java spring
Mar 09 '11 at 23:20
source share
2 answers

There are several passes in the spring context file, so the question is which skip are the available properties. Unfortunately, <import> tags are processed at an earlier pass than bean declarations (for example, one for your PropertyPlaceholderConfigurer ), so it will not be available in the form that you are trying to use.

What you're (probably) trying to do is a common thing in Spring, with many different solutions. They often include modifying your assembly to make an injection. Overflow / overflow stacking for spring environment configuration should appear. I read spring 3.1 will provide the ability to allow configuration for each environment (so use the properties file "this" if I am building the "test", this if I am building the "dev", etc ..), but I don’t know a lot about it at this moment.

+2
Mar 09 '11 at 23:33
source share

Import resources are allowed before PropertyPlaceHolderConfigurer (BeanFactoryPostProcessor) allows property owners. You will need to specify the resolved resource name in your import.

Since PropertyPlaceHolderConfigurer is a BeanFactoryPostProcessor , it is called as soon as the bean definitions are loaded from the Spring configuration files.

+3
Mar 09 2018-11-11T00:
source share



All Articles