How to load data from properties file in Maven?

I have migrated to Maven project (using Spring) where I don't need to use my old *.xml config files.

The adaptation was easy but what I still can't figure out is: how to let know to my project that I have properties file and wanna use it?

(If you know how to register properties file in POM, please add some brief description how to load data from this file. (if there is any significant difference in using )


In old project, I had just spring-mvc-dmo-servlet.xml config file, where I put every configs (like "scan all components in my projects, cus I don't wanna declare them explicitly"...

If I wanted to let my spring project know I have special file (In this case with content what I wanna use - I had to put following code into the config file -

<util:properties id="countryOptions" location="classpath:../" />

... only after that, i could wire the content from the file with fields in my classes...

like this

private Map<String, String> countryOptions;

(but now I don't have any spring-mvc-dmo-servlet.xml anymore, now I have only POM.xml and in POM my old expression doesnt work ofc )

So my question is:

What I have to put into my POM to say my spring project "HEY THERE IS SPECIAL FILE !"

And how to wire it (#{countryOptions} or ${countryOptions} or something else)

2 answers

  • answered 2018-01-14 11:30 Mumrah81

    You need to use a maven plugin to load the properties from file

    One of them is


    In one of our spring boot projects, the path to a property file is passed trough command line using the option:


    Then to get the values:

    /** The property to get. */
    private String propertyToGet;

    You can also take a look at @PropertySource annotation



  • answered 2018-01-14 11:30 Pooja Aggarwal

    You can create a property reader in which you can use inputstream reader to read a specific file from classpath or specific location and then create the bean of that property reader using @Bean annotation in your configuration class.