2

Could you recommend me the way good way how to split web application and API+db stuff into two maven modules (with one parent) ? I am struggling mainly with Spring configuration.

<Parent project>
  -> <web project> (contains spring mvc,servlets,jsps, controllers...)
  -> <api project> (contains spring hibernate cfg, db connection, dao`s, db business rules etc...)
pom.xml

API project is packaged into jar and it`s dependency for WEB project (which produces war file for jetty)

Setup maven structure is easy but i wonder if it`s possible and wise split spring configuration across both modules. DO you know any sample which works in this way or you see any problem with this configuration ?

Martin V.
  • 3,560
  • 6
  • 31
  • 47
  • why not? I used to do that. :) – Adrian Shum Oct 03 '12 at 05:37
  • I would consider moving the db connection config into the web. that way a spring-test application context can easily bootstrap the api project to execute integration tests without duplicating much of the configuration. it only contains a alternative dataSource. the api in that way just assumes a correct datasource without knowing it so it can be switched. – wemu Oct 04 '12 at 15:39

1 Answers1

0

For a small project, one module for the frontend and another for the backend is usually enough.

Create 2 Spring applicationContext.xml files and make the one in the web project import the one in the api project with something like this:

<import resource="classpath*:/config/backendApplicationContext.xml" />

So the beans in the frontend can reference beans in the backend without knowing exactly how they are being instantiated and wired together, which is good.

cahen
  • 15,807
  • 13
  • 47
  • 78