Pergunta

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

  • Core
  • Backend A - depending on Core (& possibly Backend B)
  • Backend B - depending on Core & Backend A
  • Frontend A - depending on Backend A & B
  • Frontend B - depending on Backend A & B

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:

  • Creating the Core- and Backend-Extensions as WebApplications does not work, as they then have their own ClassLoaders and Contexts, no injection possible
  • Exporting the extensions as libraries to the tomcat and including them into each Frontend-WebApplication does not ensure that the services are the same, also the annotation-based configuration does not work

Whats the best way to solve this?

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top