PDA

View Full Version : Dynamically Adding Controllers to a Spring MVC Web Module



Beta User
May 22nd, 2008, 11:57 AM
I am trying to deploy a Spring MVC web app that is deployed in one bundle and then has its controllers published in a separate bundle. My goal here is to have my web app bundle discover its Controllers dynamically, i.e. Controllers the web app will not know about until they are registered.

I have done this using a an OSGI ServiceListener and it works fine, but I am moving to s2ap and wanna know if something like Web Modules would allow me to do this.

Is there a way to deploy a Web Module and then deploy a second bundle with Controllers and get these Controllers added to the original web app?

Thanks,
Jim

Sam Brannen
May 24th, 2008, 04:31 AM
Hi Jim,

Both the Web Module and Shared Services WAR deployment formats allow you to use Spring-DM to consume services from the OSGi Service Registry. Thus, if you publish a Controller as a service in one bundle (i.e., via <osgi:service ... />), you should be able to reference it in your Web Module or Shared Services WAR (i.e., via <osgi:reference ... />) and then use the reference to the Controller as a standard bean in your Spring MVC application context.

Regards,

Sam