Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java web application modularize with spring

I'm trying to build a project structure like this:

Project
|--Web_module.war
    |--Data_module.jar(Spring)
    |--Util_module.jar
    |--other public api...

which means, different modules should be packed into different jars, so i have to have more spring configurations(application-context.xml) for different modules (e.g. for data module and for web module).

My question, how could I organize all the configuration files to include them correctly in the web module.

Thanks in advance.

like image 211
Jaiwo99 Avatar asked Mar 25 '26 09:03

Jaiwo99


1 Answers

Plan to have a single eclipse project for each jar file that you anticipate.

Choose the jars files / eclipse projects as per your project functionality to be modular and self contained, as far as possible.

Use junit tests in each eclipse project to thoroughly test individual projects/modules, using spring unit test support

Each eclipse project will contain its own spring config context file eg Util_module project might contain a util-context.xml

Finally have an eclipse dynamic web project as a wrapper web application which will aggregate all your "module" projects

UI artifacts like HTML, JS, JSPs, etc plus java code which uses web application contexts like controllers, servlet filters etc should be included in the eclipse web project

In the eclipse web project's java build path, but the module "projects" as "required" projects

In the eclipse web project's deployment assembly, add module "projects" as dependencies.

now when you build-all and deploy the web app, all depending module projects will compile and deploy as well, but more importantly, all project functionality will be divided into seperate modular projects

setup dependencies between projects with care, so as not to introduce cyclic dependencies

dont be afraid to refactor project structure when needed to maintain clean and relevant modules

like image 158
Ganesh Ghag Avatar answered Mar 27 '26 04:03

Ganesh Ghag