Spring BlazeDS Integration

Tuesday, June 1, 2010 Posted by Sanka Senevirathna

Spring BlazeDS Integration






1. Configuring and Using the BlazeDS


MessageBroker with Spring



MessageBroker is the heart of the Spring BlazeDS Integration.
When HTTP messages come from Flex client will be routed through the
Spring DispatcherServlet to the Spring-managed MessageBroker.

There is no need to configure the BlazeDS MessageBrokerServlet when using the
Spring-managed MessageBroker.





2. Configuring the Spring DispatcherServlet


web.xml is the heart of the j2ee web project.So we have to configure it because
each an every request is map to web.xml.

The DispatcherServlet must be configured in web.xml to bootstrap a Spring
WebApplicationContext. For example:





Spring MVC Dispatcher Servlet
org.springframework.web.servlet.DispatcherServlet

contextConfigLocation
/WEB-INF/config/web-application-config.xml

1



3. Configuring the MessageBroker in Spring


A simplified Spring XML config namespace is provided for configuring the MessageBroker in
your WebApplicationContext. To use the namespace support you must add the schema location
in your Spring XML config files. A typical config will look something like the following:




...



Following XML config namespace tags makes the Spring BlazeDS Integration configuration tags available under the flex
namespace in your configuration files. The above setup will be assumed for the rest of the
configuration examples to follow. For the full detail of every attribute and tag available in the



config namespace, be sure to refer to the spring-flex-1.0.xsd as every element and attribute is
fully documented there. Using an XSD-aware XML editor such as the one in Eclipse should
bring up the documentation automatically as you type.

At a minimum, the MessageBrokerFactoryBean must be configured as a bean in your
Spring WebApplicationContext in order to bootstrap the MessageBroker, along with a
MessageBrokerHandlerAdapter and an appropriate HandlerMapping (usually a
SimpleUrlHandlerMapping) to route incoming requests to the Spring-managed
MessageBroker.

These beans will be registered automatically by using the provided message-broker tag in
your bean definition file. For example, in its simplest form:






This will set up the MessageBroker and necessary supporting infrastructure using sensible
defaults. The defaults can be overriden using the provided attributes of the message-broker
tag and its associated child elements. For example, the default location of the BlazeDS XML
configuration file (/WEB-INF/flex/services-config.xml) can be overridden using the
services-config-path attribute. The MessageBrokerFactoryBean uses Spring's
ResourceLoader abstraction, so that typical Spring resource paths may be used. For
example, to load the configuration from the application's classpath:



The equivalent MessageBrokerFactoryBean definition using vanilla Spring configuration
would be:








Note especially that with the message-broker tag, it is not necessary to assign a custom id to
the MessageBroker, and it is in fact discouraged so that you won't have to continually reference
it later. The only reason you would ever need to provide a custom id is if you were bootstrapping
more than one MessageBroker in the same WebApplicationContext.
Labels: , , ,

Post a Comment