Frage

I'm trying to integrate my spring application with magnolia through the blossom module, but I'm having trouble understanding how to do this.

I've read alot on this subject, but I still don't actually know how my web.xml and applicationContext.xml should look like.

Should in my web.xml file have the 2 magnolia listeners and the spring listener and have 2 servlets one for blossom and one for spring? And then how should my applicationContext look like?

Could you help me in giving me an example of a working integration of web.xml and applicationContext.xml? I've looked everywhere on the web but the web.xml is nowhere.

Thank you very much :)

War es hilfreich?

Lösung

There's a sample for Blossom that is a full webapp setup. Have a look at the web.xml and applicationContext.xml there.

The sample is based on the magnolia-empty-webapp project which is intended as a starting point that you can build on.

In the sample you'll see that the usual Spring listener isn't in web.xml and that there's no DispatcherServlets in there either. Instead the task of starting spring is done by the samples module. The module also creates a BlossomDispatcherServlet which is used to render templates and paragraphs in the rendering process. The reason for this is that when Magnolia starts up it will go into install/update-mode and show the installation UI. At this point you don't want Spring to have been initialized because if you have beans that rely on Magnolia they will fail to start when Magnolia isn't ready. So instead Spring is started by the module.

However, if your beans are not going to depend on Magnolia than you can safely add Springs listener to web.xml and just start you BlossomDispatcherServlets from the module.

Another thing that's probably helpful to know is that Magnolia renders using a Filter and that filter will process all requests that come in unless they have been excluded. So if you add servlets to web.xml you'll want to exclude their url-patterns from Magnolias filter.

Another option which is much more straight forward is to add your servlet to your modules descriptor xml file instead. Then Magnolia will pick them up and call them from its filter. The documentation for the module descriptor is here.

So in conclusion, I would recommend starting Spring using a module and adding servlets to the modules descriptor xml. Configuring things in web.xml is also a viable option but you need to take into account how that interacts with the install/update -phase and the request routing.

Andere Tipps

Marius,

The docs for Blossom touch on how to configure your web.xml file.

Specifically, if you're starting Spring in your own module, you'd need to add this to your web.xml file before the Magnolia context listener:

<listener>
<listener-class>info.magnolia.module.blossom.support.ServletContextExposingContextListener</listener-class>
</listener>

Additionally, you'd need to extend your module class to initialize and destroy the Blossom dispatcher servlets, something like so:

public class BlossomSampleModule extends BlossomModuleSupport implements ModuleLifecycle {

public void start(ModuleLifecycleContext moduleLifecycleContext) {
        initRootWebApplicationContext("classpath:/applicationContext.xml");
        initBlossomDispatcherServlet("blossom", "classpath:/blossom-servlet.xml");
    }

public void stop(ModuleLifecycleContext moduleLifecycleContext) {
        destroyDispatcherServlets();
        closeRootWebApplicationContext();
    }
}

Hope that helps a bit!

Sean

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top