Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Context Properties and Bean Initialization

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm using Spring 3.1 and Tomcat 7.0.25. I'd like to get some custom property files loaded before the Spring Container processes my applicationContext.xml and initializes some beans in there. So after some research I found that a nice new way to do something like this in 3.1 is to use a custom ApplicationContextInitializer class. I tied it in my web.xml like this:



Then I wrote my class here:



It all works fine except for one Major problem. Beans inside my applicationContext.xml are getting initalized before my ContextPropsLoader code is getting executed. I know this by the errors it is showing, and by running it in the debugger and seeing the errors before it gets to the ContextPropsLoader code:



The db.driver.class.postgresql property is defined in my ContextPropsLoader, but too late after bean initialization.

Suggestions? Anyway to get that code to run sooner or the beans to initialize later?

Thanks for reading.
 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you added ContextLoaderListener in your web.xml ?

Thanks
 
Db Riekhof
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Manish Sridharan wrote:Have you added ContextLoaderListener in your web.xml ?

Thanks



Yes, I had the listener defined just as you say in web.xml. I moved it up to the top, and it still doesn't matter, same error.
 
Ranch Hand
Posts: 196
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you use PropertyPlaceHolderConfigurer ?
 
See where your hand is? Not there. It's next to this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic