Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 have 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.

like image 467
user523078 Avatar asked Nov 28 '10 17:11

user523078


People also ask

What is Maven Multi-Module?

A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom. The submodules are regular Maven projects, and they can be built separately or through the aggregator POM.

What is multi-module in spring boot?

A Spring Boot project that contains nested maven projects is called the multi-module project. In the multi-module project, the parent project works as a container for base maven configurations. In other words, a multi-module project is built from a parent pom that manages a group of submodules.


1 Answers

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.

like image 96
user523078 Avatar answered Oct 19 '22 23:10

user523078