Announcement Announcement Module
No announcement yet.
validation of config.xml before creating container Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • validation of config.xml before creating container

    is it possible to take a beans config file and validate it prior to passing it as a constructor arg to a configurable application context?

    the only real way that i can think of (and hopefully there's a better solution)
    would be to simply try/catch the

    new ClassPathXmlApplicationContext("classpath:/foo/bar.xml")

    and if it throws a BeansException, then you know the file is no good?

    by no good or valid in this sense i mean, can the container create everything that's inside it properly - like are all the beans in the classpath, do the constructor and/or property arguments work, etc. - i'm not talking about a well-formed XML, mind you.

    thanks in advance.

  • #2
    As far as I know - no. Actually I doubt it's really possible to do the full verification without actual initialization - sure it could work for simple beans, but with more complex stuff like factories and aop it gets very hairy.

    The best way imo is to write a simple integration test that loads the context. It will catch everything except classloading stuff.


    • #3
      yeah, i've got an application that's supported by many (hundreds) of different config files, and they're created/modified by many different ppl. a single mistake and all bets are off.

      i was trying to avoid building a lot of scaffolding around those files. thanks though, for the reply


      • #4
        May want to see if Spring IDE project contains code that does this.

        For extreme reliability you would probably want to verify a config file before you find out it is incorrect during actual use, not only during integration testing. Of course, not always possible.