Results 1 to 3 of 3

Thread: How to load data during startup - design question?

  1. #1
    Join Date
    Sep 2007
    Posts
    15

    Default How to load data during startup - design question?

    I am new to tomcat and spring, so thanks in advance for being polite.

    I will have to parse a fairly large XML file and store it in memory as a HashMap so other spring web apps have access to this class.

    How would I go about doing this? Can this HashMap be treated as a DAO and I can ask other spring objects to ingest it in their app?

    How can I force tomcat to load this HashMap during start time, so the file is populated and loaded only once?

    Thanks,
    Bob

  2. #2
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Have you looked at the Lifecycle interfaces?
    http://static.springframework.org/sp...tory-lifecycle
    Barracuda Networks SSL VPN Lead Developer
    http://pramatr.wordpress.com
    http://twitter.com/karldmoore
    http://www.linkedin.com/in/karldmoore
    Any postings are my own opinion, and should not be attributed to my employer or clients.

  3. #3

    Default

    Hi.
    Unless I am mistaken, you can do this by simply declaring your bean (the one who loads the XML and store it in a map) as a Spring bean, with the defaut scope, i.e. Singleton. The XML loading and the Map populating goes in an init-method (can be configured via xml or via JSR 250 annotation @PostConstruct).
    This bean can then be injected into any other bean needing him.

    Regards.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •