Announcement Announcement Module
No announcement yet.
PropertyConfigurer with packaged files? what about xml files? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • PropertyConfigurer with packaged files? what about xml files?

    (1) I was wondering if the PropertyPlaceholderConfigurer had the capability, or perhaps another class like it, to load XML files like it would a property file?

    For example maybe I have that looks like:

    and then of course in applicationContext can refer to their values as ${car.type}

    but is it possible to use XML format for these properties? so maybe config.xml looks like:

    and refer to their values the same way.

    (2) Can I reference a property file which is within a package, not at the root?

    Currently I use:

    to load my property file, however I had to move my properties file to root of classpath to get that to work.

    How do I refer to it if it is under a package like

    I tried like that and it couldnt find it.

  • #2
    The answer to the first question is no. PropertyPlaceholderConfigurer was not designed to load xml files, it only works with standard java property files. The reason for that is simple: xml involves logic in the specification of properties (for example in your case it is logic that a car has a type or a colour) so an xml parser extrapolating that properties cannot be done to be "general": it has to be specific.
    Since Spring is open source, you could open the PropertyPlaceholderConfigurer class and learn how it works, and then maybe extend it or write something similar, that can understand your specific xml property file.

    For the second question, yes, you can put properties file wherever you want, even in external jars, as long as the jar or the path IS on the classpath of the application. To access the correct package, simply use the standard package "Unix-style" navigation: