Question: I'm trying to design the architecture of a medium-sized web application in Java and I would like to get some advice on how to do it.

The project consists on a base website plus a number of modules. For instance, one module would provide user registration, another module would offer a web service, and so on...

Whenever I need to deliver the application to a new customer, the ideal thing would be to pick up the modules he wants, do some theming (css, images, maybe jsp) and developing the custom modules he may need, if any.

I've taken a look to maven multi module projects, war overlays, but I find it difficult to partition the application, especially in regard to the modules' configuration (for example, merging a global spring configuration from the modules). Can somebody point me to an example of such a system? Thanks in advance!

Answer: 
merging spring configuration is easy. In each module, package up a spring context file in it's /WEB-INF/classes directory. When you overlay, all classes and resources in WEB-INF classes in the dependency will be put into WEB-INF/classes in your app. (ps, this also works if you package as .jar instead, but you won't be able to overlay .jsp files if you do)

Then it's just a matter of importing them. This is best done by using a set pattern to find the files. Here's an example:

```
<import resource="classpath*:/module/*-context.xml" />

```

This will import all the classpath resources that match this pattern.

Annotation based example:

```
@Configuration
@ImportResource(value={"classpath*:/module/*-context.xml"})
public class MyConfiguration { ... }

```

It's the web.xml configuration that will cause you more trouble than anything if you have the need to do any web.xml customizations in modules. You could use servlet 3.0 for this of course, but it requires the right server to deploy on.
fwiw, after some experience with plain Spring import we developed tiny framework for osgi-less modularity for Spring. The first problem with import is the bean name clashes you can not have same-named singleton in two contexts, and many other hassles.. tbc <https://github.com/griddynamics/banshun>

--
Mike