• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring MVC read again applicationContext.xml?

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a curious problem... When the Tomcat starts my application, the ContextLoader read my bean definitions in the applicationContext(we split in some files), and when the Spring DispatcherServlet start, read again!

So the problem is, after DispatcherServlet read, I take two hibernate Session Factorys! The session factory created by ContextLoader and the session factory created by DispatcherServlet. That cause a big problem. Somebody know why this happen? And how avoid the second read?

The log:



The Hibernate Configuration



The applicationContext.xml (that import some other files, that contain beans definitions)



In some application file that was imported, I have the bean definition that is extended by all the DAO classes:



Thanks
[ September 28, 2007: Message edited by: Luciano A. Pozzo ]
 
Luciano A. Pozzo
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I found the problem. So I am posting the solution bacause somebody could have the same situation:

My application context was divided in some files for make easy the maintenance. And these files had been grouped in a main file through the tag import of spring.

The problem is that the ContextLoaderListener read and load the bean definitions of this "main file" and after the DispatcherServlet of spring mvc do the same thing again. So what happen?! I have two differents sessionFactory objects because was load twice. Then the OSIV do not work, because always open and close one session. That it is not the one used by the Persistence Manager.

So, what I did to solve. I divided the main file in two. One with the spring mvc definitions (beans that spring mvc need). And other with my business and data access (includes the sessionFactory). So, the Spring DispacherServlet load the definitions that need and the ContextLoaderListener the other one, and everything is loaded once and works.

Pay attention that Spring DispactherServlet read the xml using the name of the servlet (that you defined) more -servlet.xml. Example:



(Your xml should be dispatcher-servlet.xml)

And in your contextConfigLocation, put the other xml. Like this:




Hope that it's clear.

Thank's
 
If you have a bad day in October, have a slice of banana cream pie. And this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic