3.3. Using the remoting-destination Tag

The remoting-destination configuration tag can be used to export existing Spring-managed services for direct remoting from a Flex client. Given the following Spring bean definition for a productService bean:

<bean id="productService" class="flex.samples.product.ProductServiceImpl" />

and assuming the existance of a Spring-managed MessageBroker configured via the message-broker tag, the following top-level remoting-destination tag will expose the service for remoting to the Flex client as a remote service destination named productService:

<!-- Expose the productService bean for BlazeDS remoting -->
<flex:remoting-destination ref="productService" />

By default, the remote service destination exposed to the Flex client will use bean name of the bean being exported as the service id of the destination, but this may be overridden using the destination-id attribute on the remoting-destination tag.

An alternate way of using the remoting-destination tag is as a child element of an top-level bean definition. This is even more concise and works well if you don't have a need to keep your domain-layer bean definitions separate from infrastructure concerns such as Flex remoting. (Keep in mind that keeping them separate can lead to easier testability of the core domain layer.) The following achieves the equivalent result to the previous example:

<bean id="productService" class="flex.samples.product.ProductServiceImpl" >
	<flex:remoting-destination />

The methods that are exposed to be called by the Flex client can be more tightly controlled through use of the include-methods and exclude-methods attributes of the remoting-destination tag. The BlazeDS channels over which the destination is exposed can also be controlled using the channels attribute. (These attributes are available whether using the top-level or the nested version.) A more extensively customized example would look something like:

<flex:remoting-destination ref="productService" 
    include-methods="read, update" 
    exclude-methods="create, delete" 
    channels="my-amf, my-secure-amf" />

The remoting-destination tag is transparently configuring a RemotingDestinationExporter bean instance for each bean being exported. The equivalent full bean syntax without the namespace support would be:

<!-- Expose the productService bean for BlazeDS remoting -->
<bean id="product" class="org.springframework.flex.remoting.RemotingDestinationExporter">
    <property name="messageBroker" ref="_messageBroker"/>
    <property name="service" ref="productService"/>
    <property name="destinationId" value="productService"/>
    <property name="includeMethods" value="read, update"/>
    <property name="excludeMethods" value="create, delete"/>
    <property name="channels" value="my-amf, my-secure-amf"/>