my dog learned polymorphism*
The moose likes Other Application Frameworks and the fly likes Can I read Spring configuration twice in my applction? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Can I read Spring configuration twice in my applction?" Watch "Can I read Spring configuration twice in my applction?" New topic
Author

Can I read Spring configuration twice in my applction?

avseq anthoy
Ranch Hand

Joined: Apr 27, 2004
Posts: 104
Because I define Qurtzs in the configuration.
I think If I read configure twice, the quartz will start twice.
But it didn't. The application seem to work normally.
So I want to confirm that I can read Spring configuration not only once any where in my appliction. right?


My Way,My Pace
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Anthony,

What do you mean by �reading the configuration twice�? As far as I know you use the appropriate implementation of the ApplicationContext and allow the container to load the configuration and initialize the bean factory. This will happen only once after initializing the context. Something like this:



In a web application you have to configure the context listener in your web.xml file (or use a specific servlet with load on startup = 1):



And again is the container that loads the configurations.
My point here is that the container should be the one loading the configuration files and initializing the bean factory. Could you detail what do you mean by loading or reading the configuration twice?
Regards.


I think, therefore I exist -- Rene Descartes
avseq anthoy
Ranch Hand

Joined: Apr 27, 2004
Posts: 104
Hi Tanase :
Thanks for your reply.
The meaning of reading Spring configuration twice is like following code

I use ClassPathXmlApplicationContext to read xml configuration twice.
It seem no error in the log. So I want to confirm taht I can load Spring
configuration not only once and Spring container will still work normally.
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Here there is my two cents bet: the ClassPathXmlApplicationContext also implements the BeanFactory interface. This makes the point that after initializing the app context this class will also load all beans from the configuration file(s). By default these beans suppose to be singletons (unless you specify otherwise). I would say that you�d have two different bean factories instances, loading the same beans. Just for the argument sake you can try running this code:



Where "beanName" is the name of one of your beans as it appears in the config file. This should also be loaded as a singleton (default).

And again just for the argument sake: I personally could not see any treason or benefit from having two different bean factories.

Regards.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can I read Spring configuration twice in my applction?
 
Similar Threads
I need a small project to do with spring and hibernate.
Spring MVC - Url Handling Problem
struts2 Vs spring mvc
Spring config bloat
Read key and value from properties file