Home Server app with CloudIQ
Server app with CloudIQ PDF Print E-mail
Written by Administrator   
Saturday, 13 February 2010 00:00

Spring Server app with CloudIQ Fabric Application

Spring Hello World Java Bean

Below is the simple, HelloWorldBean that we are going to fabric-enable using Spring.

Note that this is a plain, old, Java object (POJO), that does not require any Fabric APIs.

HelloWorldBean.java

(in tutorial_samples/java/spring_hello_world/spring_hello_world_app/com/appistry/samples/spring_hello_world/bean)

1. package com.appistry.samples.spring_hello_world.bean;
2. 
3. public class HelloWorldBean implements IHelloWorldBean
4. {
5. 	public String greet(String name)
6. 	{
7. 		return "Hello World, " + name;
8. 	}
9. }

Spring configuration file for HelloWorldBean

The following Spring application context XML is used by the Hello World fabric application to load the

HelloWorldBean as a Java component in the fabric.  In this application context XML, we wire a local instance of our POJO.

Note that this is a typical Spring bean definition with no fabric specific settings.

spring_hello_world_bean.xml (in tutorial_samples/java/spring_hello_world/spring_hello_world_app)

1. <?xml version="1.0"?>
2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
3. <beans>
4.     <bean id="HelloWorldBean" class="com.appistry.samples.spring_hello_world.bean.HelloWorldBean"/>
5. </beans>

Spring Hello World Component XML Definition

Next, we identify the HelloWorldBean Spring bean as a fabric Java component.

This is done using fabric component definition XML as seen below.

First we define a name for our component. This name can match the ID or name used in the Spring configuration file for the Spring bean.

Last, we specify the spring-bean tag, using the ID or name of the Spring bean from the Spring configuration file.

spring_hello_world_component.xml (in tutorial_samples/java/spring_hello_world/spring_hello_world_app)

1. <?xml version="1.0" encoding="utf-8"?>
2. <java-components xmlns="http://www.appistry.com/ns/component"
3. 	             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4.                  xsi:schemaLocation="http://www.appistry.com/ns/component eaf-component.xsd">
5.     <component name="hello_world_component" default-timeout="5">
6.         <spring-bean name="HelloWorldBean"/>
7.     </component>
8. </java-components>
Spring bean

Identifies the bean name that you want this component to reference

Spring Bean Factory

Appistry EAF uses the Spring BeanFactoryLocator pattern to locate and load your Spring application contexts.

We do not specify that you must use one ApplicationContext type or another.

That decision is yours. To do this, you provide an application context XML file defining a bean for the type of

Spring ApplicationContext implementation you want to use. The beanRefFactory.xml file below defines a factory bean

"myBeanFactory" of type ClassPathXmlApplicationContext.  beanRefFactory.xml

(in tutorial_samples/java/spring_hello_world/spring_hello_world_app)

 

der: 1px solid #d4d4d4;">
1. <?xml version="1.0" encoding="UTF-8"?>
2. <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
3. <beans>
4.     <bean id="myBeanFactory" class="org.springframework.context.support.ClassPathXmlApplicationContext">
5.         <constructor-arg value="spring_hello_world_bean.xml"/>
6.     </bean>
7. </beans>

Spring Hello World Application XML Definition

Now we tie together all the pieces of our Spring fabric application using Fabric Application Definition XML. First, we tell the fabric how to load our Spring application context using the <spring> tag. Second, we include our Java Spring component using the <components> tag. Last, we list the jars loaded by our fabric application using the <java-libs> tag.

spring_hello_world_app.xml (in tutorial_samples/java/spring_hello_world/spring_hello_world_app)

01. <?xml version="1.0"?>
02. <!DOCTYPE app SYSTEM "FabricApp.dtd">
03. <app name="spring_hello_world_app" version="4.2">
04.     <spring>
05.         <bean-factory-locator bean="myBeanFactory" resource-location="beanRefFactory.xml"/>
06.     </spring>
07.     <components>
08.         <file name="spring_hello_world_component.xml"/>
09.     </components>
10.     <java-libs>
11.         <file name="spring_hello_world_bean.jar"/>
12.         <file name="spring.jar"/>
13.         <file name="commons-logging.jar"/>
14.     </java-libs>
15. </app>

 

Last Updated on Saturday, 13 February 2010 18:10
 
Banner
Copyright © 2010 Bloberry IT Consulting. All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.