Question

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.

Was it helpful?

Solution

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

OTHER TIPS

For your modules to publish their own configuration (and your main application to detect them automatically), you can, in your main applicationContext.xml, import other context.xml files from the classpath using a pattern with wildcards :

<import resource="classpath*:conf/moduleContext.xml" />

This tells spring to find and read files in all jars that match conf/moduleContext.xml. Note there is a little limitation to this : you must have your context files in at least one directory (not in the root of the classpath). This is why in my example you have de "conf" directory.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top