Simple Flex Webapp

David Winterfeldt

2009


The simple Flex webapp is based on the Simple Spring MVC Form Annotation Configuration Webapp. It's the same except the HTML results on the search page have been replaced with a Flex application and services for Flex were configured on the server using Spring BlazeDS Integration and Adobe BlazeDS.

Adobe Flex can run in a Flash plugin available for most browsers and operating systems. Applications can also be deployed as desktop application using Adobe AIR. Adobe BlazeDS is an open source project for integrating server side Java with a Flex client for remoting and messaging. Spring BlazeDS Integration provides reduced configuration and ease of use on top of Adobe BlazeDS.

[Note]Note

The project is configured with Flex Builder (Eclipse plugin) and also can be run from the command line.

$ mvn jetty:run

1. Web Configuration

This is a standard Spring web application configuration except a DispatcherServlet specifically for handling Flex remoting requests has been added and the Spring config specified will configure Spring BlazeDS Integration.

/WEB-INF/web.xml
                
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0" metadata-complete="true">

    <display-name>simple-form</display-name>
    
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/*-context.xml
        </param-value>
    </context-param>

    <filter>
        <filter-name>encoding-filter</filter-name>
        <filter-class>
            org.springframework.web.filter.CharacterEncodingFilter
        </filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>encoding-filter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <servlet>
        <servlet-name>simple-form</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<init-param>
			<param-name>contextConfigLocation</param-name>
			<param-value></param-value>
		</init-param>
    </servlet>

    <servlet>
        <servlet-name>spring-flex</servlet-name> 1
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/flex/flex-servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
        
    <servlet-mapping>
        <servlet-name>simple-form</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>spring-flex</servlet-name>
        <url-pattern>/spring/*</url-pattern> 2
    </servlet-mapping>

    
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

</web-app>
                
            
1 Spring BlazeDS Integration servlet.
2 Mapping Spring BlazeDS Integration servlet to handle all requests to '/spring/*'.