0

My web application have 2 modules:

  • core (service, repository/dao, entities, etc.)
  • web (views, controllers, converters, filters, etc.)

The web module have the dispatcher-context.xml with Spring MVC definitions.

I'm confused where to put the Spring Root Application Context (application-context.xml) with Data/JTA definitions - Web module or in Core module?

Thanks in advance!

outlookrperson
  • 2,761
  • 7
  • 32
  • 49

1 Answers1

1

The root application context is meant to contain beans that should be available to every component in the final application. The servlet application context is meant to contain beans that should only be available to your DispatcherServlet stack. This question and its answer explain how Spring manages them.

Core should contain the root application context as it declares services, repositories, and entities that will be available to the whole application.

Community
  • 1
  • 1
Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • Thanks @SotiriosDelimanolis, but as far as I can see, after further researches, both root application-context.xml and servlet-context.xml are declared in web.xml. So both resides in web module, right? – outlookrperson Dec 09 '13 at 22:43
  • @rperson Careful, just because you _declare_ the application context location in `web.xml` doesn't mean it has to be in the same package. Another thing to consider is this: will you have many web modules? Will they be using the same application contexts? If no, then it makes sense that each web modules has its own application context. – Sotirios Delimanolis Dec 09 '13 at 23:16