Spring boot: loading resources like application.properties

Spring Boot searches application.properties

in different places: in the classpath, in the current folder, in the / config folder, etc.

Is there an easy way to load any resource in the same way?

For example, I want to upload files:

  • a.txt
  • b.xml
  • c.properties

and parse them yourself, not as properties files.

Is there an easy way to ask spring boot to find them as if it is looking for application.properties in different places?

+3


source to share


1 answer


The short answer is that there is no way to ask Spring Boot. However, you can view all of their code. If you look into your ConfigFileApplicationListener class, you can see how they have DEFAULT_SEARCH_LOCATIONS defined as a list of locations to look for configuration files, and they store that in a collection. They then use the ResourceLoader to scroll and check for the right resource at each location. If you go through your code and resource documentation , I believe you can create your own service to get the file from a possible list of locations.



+1


source







All Articles