• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Spring MVC read again applicationContext.xml?

Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • 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:

[ September 28, 2007: Message edited by: Luciano A. Pozzo ]
Luciano A. Pozzo
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • 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.

You firghten me terribly. I would like to go home now. Here, take this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic