DDD, JPA and Multi-Module Maven
I'm trying to configure and Maven multi-module project with Spring / JPA. Here's the general layout. I have a root module with 5 children modules.
backoffice (root maven module) | -(maven module)-----core (this is where persistence.xml and entityManager stuff resides). | -(maven module)-----employee (employee related entities, controllers, etc.) | -(maven module)-----vendor (vendor related entities, controllers, etc.) | -(maven module)-----customer (customer related entities, controllers, etc.) | -(maven module)-----web (contains all the web stuff).
I h开发者_运维百科ave all the jpa stuff in core/src/main/resources/META-INF (persistence.xml, spring-context w/ EntityManagerFactory, dataSource, etc.). The idea is I want to share the persistence stuff across all sub-modules (employee, vendor and customer).
The problem is that when the web app starts up, it can't find the EntityMangerFactory. If I setup the JPA stuff in each sub module (employee, vendor and customer), then it works.
How do I setup all my persistence related stuff in core and then share it across the other modules?
Thanks in advance.
Well, here is the solution that I ended up using in case anyone is interested.
http://labs.bsb.com/2010/11/configuring-modular-jpa-applications-with-spring/
Some of the responders asked why would I want to setup the project this way in the first place. Well the reason is modularity. I want everything in small testable and deploy-able units. Ultimately we will weave OSGI into the mix so the customer can choose which modules they want to install. Each module must have the ability to run on its own.
If the employee, vendor and customer entities and controllers are so logically separate as to need them in separate modules, then I would say that clearly they should have their own entityManager.
If you want to have a single webapp, and a single entitymanager, then why do you want to have separate modules for each chunk of entities? Just stick employees, vendors and customer in core, with the entity manager, and be done.
Or, give each one their own entitymanager, (and probably each one their own webapp)
精彩评论