maxdev
maxdev

Reputation: 2576

Modular web application with Spring

I want to create a web application splitted in extensions structured like this:

They should run in a Tomcat. Now my problem is that I still want to provide the ability to inject services from the extensions it depends on. Also, the two frontends should use the same instance of each service defined in the backend extension. It would be a cool feature if the configuration of the Extensions could happen completely annotation-based (WebApplicationInitializer and @Configuration).

What I've tried:

Whats the best way to solve this?

Upvotes: 2

Views: 1612

Answers (1)

Jakub Kubrynski
Jakub Kubrynski

Reputation: 14159

In case you want to use Tomcat your only option to share Spring context is to setup just one WebApplicaiton (initialized by WebApplicationInitializer). Of course you can still have separate modules (aka jars) with own @Configuration classes, but these configurations have to be merged in web application.

It would be more flexible if you decide to use EAR packaging. Then you can have still two separate WAR's depending on core and backend services. Then core and backend services can be shared as a parent Spring context (by using beanRefContext) and two war's (frontend A and frontend B) will extend this context

Upvotes: 3

Related Questions