Spring Deployment

The spring deployment module enables you to deploy spring based applications like any other JavaEE based applications. You have to package your spring application within a jar file containing a simple deployment plan and that's all to access this archive from other JavaEE based applications within your application server.

The spring deployment module is preinstalled in GASwerk Spring.

How it works

Here is a simple example with a Spring based "backend component" and a simple frontend using a bean from the backend.

The sample project can be downloaded here

Backend configuration

First of all you need a simple Spring based application.

Here is a very simple example:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans 
       http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    
    <bean id="test" class="net.sourceforge.gaswerk.spring.TestClass"/>
        
</beans> 

There is only one bean called test registered within the target ApplicationContext. This bean should be accessible by other applications within the application server. (The file containing this definition is called app.xml in this example)

To be able to deploy the application as standalone spring archive there must be a deployment plan within the archive called META-INF/gaswerk-spring.xml. The schema definition can be found here

<?xml version="1.0" encoding="UTF-8"?>
<spring-context
    xmlns="http://gaswerk.sourceforge.net/xml/ns/spring/springcontext-1.0" 
    xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <sys:environment>

        <sys:moduleId>
                <sys:groupId>net.sourceforge.gaswerk.samples</sys:groupId>
                <sys:artifactId>spring-application</sys:artifactId>
                <sys:version>1.0</sys:version>
        </sys:moduleId>

        <sys:dependencies>

                <sys:dependency>
                        <sys:groupId>org.springframework</sys:groupId>
                        <sys:artifactId>spring-beans</sys:artifactId>
                        <sys:version>2.0.5</sys:version>
                </sys:dependency>

                <sys:dependency>
                        <sys:groupId>org.springframework</sys:groupId>
                        <sys:artifactId>spring-core</sys:artifactId>
                        <sys:version>2.0.5</sys:version>
                </sys:dependency>

                <sys:dependency>
                        <sys:groupId>org.springframework</sys:groupId>
                        <sys:artifactId>spring-context</sys:artifactId>
                        <sys:version>2.0.5</sys:version>
                </sys:dependency>

                <!--
                ... more dependencies ...
                -->

        </sys:dependencies>

    </sys:environment>
        
    <applicationContexts>
        <applicationContext>app.xml</applicationContext>
    </applicationContexts>
        
</spring-context>

The sample project can be downloaded here

Frontend configuration

To access the registered bean from a frontend component you can use the GASwerk Spring FactoryBean called SpringContextFactoryBean. You have to set the property called beanName to define which bean you want to call (in this example the bean is called test as said before ;-) ) and the name of the applicationContext.

<?xml version="1.0" encoding="iso-8859-1"?>
        <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
                "http://www.springframework.org/dtd/spring-beans.dtd">
                
<beans>
                
   <bean id="test" 
     class="net.sourceforge.gaswerk.spring.util.SpringContextFactoryBean">
    <property name="beanName" value="test"/>
    <property name="springContextObjectName">
        <value>geronimo:ServiceModule=net.sourceforge.gaswerk.samples/
            spring-application/1.0/spring,J2EEServer=geronimo,
            name=context-0,j2eeType=GBean</value>
    </property>
   </bean>
...     
</beans>

You also have to define a dependency from your web application to the spring backend module. This can be done within the geronimo-web.xml.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:security="http://geronimo.apache.org/xml/ns/security-1.1" 
    xmlns="http://geronimo.apache.org/xml/ns/j2ee/web/jetty-1.2" 
    xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2" 
    xmlns:app="http://geronimo.apache.org/xml/ns/j2ee/application-1.2" 
    xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <sys:environment>
        
        <sys:moduleId>
                <sys:groupId>net.sourceforge.gaswerk.samples</sys:groupId>
                <sys:artifactId>web-application</sys:artifactId>
                <sys:version>1.0</sys:version>
                <sys:type>war</sys:type>
        </sys:moduleId>

        <sys:dependencies>      

           <sys:dependency>     
                <sys:groupId>net.sourceforge.gaswerk.samples</sys:groupId>
                <sys:artifactId>spring-application</sys:artifactId>
                <sys:version>1.0</sys:version>
                <sys:type>spring</sys:type>
        </sys:dependency>                       
...

The sample project can be downloaded here