I am creating a class called FileConfig
with the following annotation:
@ConfigurationProperties(locations = { "classpath:application.properties" , "${file.config.location}" })
The following line exists within 'application.properties':
file.config.location = fileinfo.yaml
Apparently, my compiler says, that the locations property has deprecated in favor of configuring the environment directly with additional locations. Can someone please help me how to configure the environment so that the variables in FileConfig
are initialized using the contents of 'fileinfo.yaml' file
Using @PropertySource("classpath:testapplication.properties")
instead of using the above line of code produces an error.
If I understand your question correctly, you specify the location of fileInfo.yaml
file in your application.properties
file. And this value should be set as location of your property class FileConfig
.
I think thats not possible because SpEL expressions are not evaluated.
Here the part of the java doc from @ConfigurationProperties
:
Annotation for externalized configuration. Add this to a class definition or a @Bean method in a @Configuration class if you want to bind and validate some external Properties (eg from a .properties file).
Note that contrary to @Value, SpEL expressions are not evaluated since property values are externalized.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.