Home > Apache Geronimo v1.0 > Documentation > Apache Geronimo v1.0 - Developer's Guide > Application frameworks > Spring |
Spring is a layered Java/J2EE application framework, based on code published in Expert One-on-One J2EE Design and Development. Throughout this article we will be using Apache Geronimo v1.0 and Spring Framework 1.2.7 as it is the latest release for production. Refer to http://www.springframework.org/ for additional details.
The focus of this article is not to show you how to customize nor develop applications with Spring but to show you the integration in Apache Geronimo. In this article you will find step-by-step instructions for configuring and deploying the sample applications provided by the framework. Some of these sample applications accept more that one configuration, we will attempt to cover all these configurations.
This article is organized in the following sections:
The following software should be installed and configured in order to run the samples covered in this article.
Geronimo is currently using the Sun ORB for RMI so it is required to use SUN JDK. These sample applications require as a minimum JDK 1.3. Refer to the following URL for details on how to download and install J2SE 1.4.2:
http://java.sun.com
Apache Ant 1.5 or later is required for building the sample application. Ant can be downloaded from the following URL:
http://ant.apache.org
This article is based on the use of SpringFramework 1.2.7.
http://www.springframework.org/
All the sample applications covered in this article will be deployed to Apache Geronimo v1.0.
http://geronimo.apache.org/
Spring comes with a series of sample applications for demonstrating the different features covered by the framework. This section provides a high level overview of these sample applications, what are the technologies each of these applications make focused on and how to make them work in Apache Geronimo.
The sample applications provided with the SpringFramework 1.2.7 are:
The Countries sample application covers the use of advanced features in the presentation layer. The Spring Countries sample application heavily focuses on:
This application lists country's code, lets you search by country code and name, allows you to export the search results in both pdf and excel formats. This application also provides three different themes and three different languages to choose from.
This sample application can be used in three different configurations:
You should have tested the copy configuration and used successfully the copy in the data base function to be able to use this configuration.
Refer to the application's readme.txt for further details.
This is the configuration by default, we will just add a Geronimo specific deployment plan to ensure the usage of the Spring jars deployed with the web application.
To create a Geronimo specific deployment plan geronimo-web.xml follow these steps.
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.0" configId="org/springframework/samples/countries"> <!-- force the usage of the Spring jars deployed with the web application --> <hidden-classes> <filter>org.springframework</filter> </hidden-classes> <context-root>/countries</context-root> <context-priority-classloader>false</context-priority-classloader> </web-app>
To build the application an Ant build script is provided, this script has the following targets available:
Run the following command from the <spring_home>\samples\countries directory.
build all
This will create the countries.war file in the <spring_home>\samples\countries\dist directory. This is the file we will use for deploying to Apache Geronimo.
To deploy the sample application we will use the command line option. Run the following command from the <geronimo_home>\bin directory:
deploy --user system --password manager deploy <spring_home>\samples\countries\dist\countries.war
In order to use the deployer tool, the Apache Geronimo server has to be running. |
Once the application has been successfully deployed you should see a confirmation message similar to this example.
E:\geronimo-1.0\bin>deploy --user system --password manager deploy \spring-framework-1.2.7\samples\countries\dist\countries.war
Deployed org/springframework/samples/countries @
http://hcunico:8080/countries
When you deploy an application from the command line using the deployer tool you will receive as a part of the confirmation message the URL (context root) for testing the application.
Open a web browser and access the following URL:
http://localhost:8080/countries
Click on the different links from the navigation menu on the left.
NOT TESTED
In countries-servlet.xml, comment on part ONLY MEMORY OR ONLY DATABASE IMPLEMENTATION. Uncomment on part MEMORY+DATABASE IMPLEMENTATION FOR COPYING FROM MEMORY TO DATABASE.
In applicationContext.xml, comment on part In memory only version. Uncomment on part In memory + Database version for copying
NOT TESTED
In countries-servlet.xml, comment on part MEMORY+DATABASE IMPLEMENTATION FOR COPYING FROM MEMORY TO DATABASE. Uncomment on part ONLY MEMORY OR ONLY DATABASE IMPLEMENTATION. You thus returned to the starting situation.
In applicationContext.xml, comment on part In memory + Database version for copying. Uncomment on part Database only version.
The ImageDb sample application make special focus on a couple of features that are not covered by any of the other sample applications. This particular features are:
ImageDb sample application uses by default MySQL, in this section we will modify the default configuration to use the Geronimo embedded database, Derby. The following steps will show you how to configure, build and deploy this sample application in Apache Geronimo.
Refer to the application's readme.txt for further details.
To create a Geronimo specific deployment plan geronimo-web.xml follow these steps.
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.0" configId="org/springframework/samples/imagedb"> <!-- force the usage of the Spring jars deployed with the web application --> <hidden-classes> <filter>org.springframework</filter> </hidden-classes> <context-root>/imagedb</context-root> <context-priority-classloader>false</context-priority-classloader> </web-app>
To create a database in Geronimo follow these steps.
CREATE TABLE imagedb ( image_name VARCHAR(255) NOT NULL PRIMARY KEY, content BLOB, description VARCHAR(255) );
Additional details on starting the server and creating databases can be found in the Administrative tasks section.
The following steps summarizes the steps needed to create a database connection pool. Refer to Configuring database pools for further details.
You now need to update the JDBC connection properties to point to the newly configured Derby database. Edit the jdbc.properties file located in the <spring_home>\samples\imagedb\war\WEB-INF directory to reflect the changes shown in the following example.
# Properties file with JDBC-related settings. # Applied by PropertyPlaceholderConfigurer from "applicationContext.xml". # Targeted at system administrators, to avoid touching the context XML files. #jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.driverClassName=org.apache.derby.jdbc.EmbeddedDriver #jdbc.url=jdbc:mysql://localhost:3306/imagedb jdbc.url=jdbc:derby:imagedb #jdbc.username=root jdbc.username= #jdbc.password=password jdbc.password= imageDatabase.lobHandler=defaultLobHandler #jdbc.driverClassName=oracle.jdbc.OracleDriver #jdbc.url=jdbc:oracle:thin:@localhost:1521:imagedb #jdbc.username=scott #jdbc.password=tiger #imageDatabase.lobHandler=oracleLobHandler
For this example we will not be testing the mail functionality of this sample application hence we will "disable" this feature. Edit the mail.properties file located in the <spring_home>\samples\imagedb\war\WEB-INF directory to reflect the changes shown in the following example.
# Properties file with mail-related settings, used for scheduled info emails. # Applied by PropertyPlaceholderConfigurer from "applicationContext.xml". # Targeted at system administrators, to avoid touching the context XML files. mail.host= #[email protected] mail.from= #[email protected] mail.to=
At this point we have done all the changes needed to the configurations in order to run this sample application in Apache Geronimo. To build the application an Ant build script is provided, this file has the following targets available:
To build the ImageDB sample application run the following command from the <spring_home>\samples\imagedb directory.
build all
This will create the imagedb.war file in the <spring_home>\samples\imagedb\dist directory. This is the file we will use for deploying to Apache Geronimo.
To deploy the sample application we will use the command line option. Run the following command from the <geronimo_home>\bin directory:
deploy --user system --password manager deploy <spring_home>\samples\imagedb\dist\imagedb.war
In order to use the deployer tool, the Apache Geronimo server has to be running. |
Once the application has been successfully deployed you should see a confirmation message similar to this example.
E:\geronimo\bin>deploy --user system --password manager deploy \spring-framework-1.2.7\samples\imagedb\dist\imagedb.war
Deployed org/springframework/samples/imagedb @
http://hcunico:8080/imagedb
When you deploy an application from the command line using the deployer tool you will receive as a part of the confirmation message the URL (context root) for testing the application.
Open a web browser and access the following URL:
You will be presented with a simple form where you can specify Name (file name alias), Content (browse the file) and Description. Try to upload a few images, you can see how these images are being stored in the Derby database by using the Geronimo Administration Console. Click on DB Manager, then click on Application corresponding to the imagedb database. Now click on View Contents for the IMAGEDB table (there should be just one table). You should see IMAGE_NAME, CONTENT and DESCRIPTION as you entered in the forms.
There were some errors while uploading images stored in long name directories, as a workaround you can upload applications from the root directory. |
JPetStore is a Spring-managed middle tier with iBATIS Database Layer as data access strategy, in combination with Spring's transaction and DAO abstractions. Can work with local JDBC transactions or JTA. JPetStore uses the same data model and demo contents as the original, well known, JPetStore; see http://ibatis.apache.org for details.
This version of JPetStore has an improved internal structure and loose coupling. This version of JPetStore also demonstrates various remoting options with Spring: Hessian, Burlap, RMI, and Web Services via Apache Axis. They are all provided out-of-the-box by the default web application. The "client" directory contains a simple command-line client that invokes the exported OrderService via all protocols.
Refer to the application's readme.txt for further details.
To create a Geronimo specific deployment plan geronimo-web.xml follow these steps.
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.0" configId="org/springframework/samples/jpetstore"> <!-- force the usage of the Spring jars deployed with the web application --> <hidden-classes> <filter>org.springframework</filter> </hidden-classes> <context-root>/jpetstore</context-root> <context-priority-classloader>false</context-priority-classloader> </web-app>
To create a database in Geronimo follow these steps.
You will need to load some sample data to run this sample application. While still in the DB Manager copy and paste the content from the attached jpetstore-derbydb-dataload.sql into the SQL Command/s: field. Make sure you select jpetstore from the Use DB: pull-down menu.
The following steps summarizes the steps needed to create a database connection pool. Refer to Configuring database pools for further details.
You now need to update the JDBC connection properties to point to the newly configured Derby database. Edit the jdbc.properties file located in the <spring_home>\samples\jpetstore\war\WEB-INF directory to reflect the changes shown in the following example.
# Properties file with JDBC-related settings. # Applied by PropertyPlaceholderConfigurer from "dataAccessContext-local.xml". # Targeted at system administrators, to avoid touching the context XML files. #jdbc.driverClassName=org.hsqldb.jdbcDriver jdbc.driverClassName=org.apache.derby.jdbc.EmbeddedDriver #jdbc.url=jdbc:hsqldb:hsql://localhost:9002 jdbc.url=jdbc:derby:jpetstore #jdbc.username=sa jdbc.username= jdbc.password=
At this point we have done all the changes needed to the configurations in order to run this sample application in Apache Geronimo. To build the application an Ant build script is provided, this file has the following targets available:
To build the JPetStore sample application run the following command from the <spring_home>\samples\jpetstore directory.
build all
This will create the jpetstore.war file in the <spring_home>\samples\jpetstore\dist directory. This is the file we will use for deploying to Apache Geronimo.
To deploy the sample application we will use the command line option. Run the following command from the <geronimo_home>\bin directory:
deploy --user system --password manager deploy <spring_home>\samples\jpetstore\dist\jpetstore.war
In order to use the deployer tool, the Apache Geronimo server has to be running. |
Once the application has been successfully deployed you should see a confirmation message similar to this example.
E:\geronimo\bin>deploy --user system --password manager deploy \spring-framework-1.2.7\samples\jpetstore\dist\jpetstore.war
Deployed org/springframework/samples/jpetstore @
http://hcunico:8080/jpetstore
When you deploy an application from the command line using the deployer tool you will receive as a part of the confirmation message the URL (context root) for testing the application.
Open a web browser and access the following URL:
http://localhost:8080/jpetstore
Click on Enter the Store, browse the catalog and place an order. Once you placed the order you can see it reflected in the table ORDERS in the jpetstore database (use the DM Manager portlet from the Geronimo Administration Console).
Refer to the application's readme.txt for further details.
To create a Geronimo specific deployment plan geronimo-web.xml follow these steps.
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.0" configId="org/springframework/samples/petclinic"> <!-- force the usage of the Spring jars deployed with the web application --> <hidden-classes> <filter>org.springframework</filter> </hidden-classes> <!-- only required if using Hibernate --> <hidden-classes> <filter>antlr</filter> </hidden-classes> <context-root>/petclinic</context-root> <context-priority-classloader>false</context-priority-classloader> </web-app>
To create a database in Geronimo follow these steps.
You will need to load some sample data to run this sample application. While still in the DB Manager copy and paste the content from the attached petclinic-derbydb-dataload.sql into the SQL Command/s: field. Make sure you select petclinic from the Use DB: pull-down menu.
The following steps summarizes the steps needed to create a database connection pool. Refer to Configuring database pools for further details.
You now need to update the JDBC connection properties to point to the newly configured Derby database. Edit the jdbc.properties file located in the <spring_home>\samples\petclinic\war\WEB-INF directory to reflect the changes shown in the following example.
# Properties file with JDBC-related settings. # Applied by PropertyPlaceholderConfigurer from "applicationContext-*.xml". # Targeted at system administrators, to avoid touching the context XML files. #jdbc.driverClassName=org.hsqldb.jdbcDriver #jdbc.driverClassName=com.mysql.jdbc.Driver jdbc.driverClassName=org.apache.derby.jdbc.EmbeddedDriver #jdbc.url=jdbc:hsqldb:hsql://localhost:9001 #jdbc.url=jdbc:mysql://localhost:3306/petclinic jdbc.url=jdbc:derby:petclinic #jdbc.username=sa jdbc.username= jdbc.password= # Property that determines the Hibernate dialect # (only applied with "applicationContext-hibernate.xml") #hibernate.dialect=org.hibernate.dialect.HSQLDialect hibernate.dialect=org.hibernate.dialect.DerbyDialect #hibernate.dialect=org.hibernate.dialect.MySQLDialect # Property that determines the JDBC implementation of Clinic # (only applied with "applicationContext-jdbc.xml") petclinic.jdbcImplBeanName=hsqlClinic #petclinic.jdbcImplBeanName=mysqlClinic # Note that OJB expects the database platform to be set in # "OJB-repository.xml" (jdbc-connection-descriptor platform).
At this point we have done all the changes needed to the configurations in order to run this sample application in Apache Geronimo. To build the application an Ant build script is provided, this file has the following targets available:
To build the JPetStore sample application run the following command from the <spring_home>\samples\jpetstore directory.
build clean
build warfile
This will create the petclinic.war file in the <spring_home>\samples\petclinic\dist directory. This is the file we will use for deploying to Apache Geronimo.
To deploy the sample application we will use the command line option. Run the following command from the <geronimo_home>\bin directory:
deploy --user system --password manager deploy <spring_home>\samples\petclinic\dist\petclinic.war
In order to use the deployer tool, the Apache Geronimo server has to be running. |
Once the application has been successfully deployed you should see a confirmation message similar to this example.
E:\geronimo\bin>deploy --user system --password manager deploy \spring-framework-1.2.7\samples\petclinic\dist\petclinic.war
Deployed org/springframework/samples/petclinic @
http://hcunico:8080/petclinic
When you deploy an application from the command line using the deployer tool you will receive as a part of the confirmation message the URL (context root) for testing the application.
Open a web browser and access the following URL:
http://localhost:8080/petclinic
Click on Find owner, enter Davis for instance (the search is case sensitive). The search will retrieve the two owners with that last name. By clicking on the owner button you can access the owner information and edit it as well as list and edit pets and visits.
The Tiles-example is simple application that shows the integration of Tiles in Web applications using Spring. This sample application includes two templates and three content JSPs. One of those templates automatically import news directly from Slashdot, TheServerside or JavaBlogs. Refer to the application's readme.txt for further details.
The following steps will show you how to build and deploy this sample application in Apache Geronimo.
Before you build this application you will need to create a Geronimo specific deployment plan geronimo-web.xml as described in the following steps.
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://geronimo.apache.org/xml/ns/j2ee/web-1.0" configId="org/springframework/samples/tiles"> <!-- force the usage of the Spring jars deployed with the web application --> <hidden-classes> <filter>org.springframework</filter> </hidden-classes> <context-root>/tiles</context-root> <context-priority-classloader>false</context-priority-classloader> </web-app>
To build the application an Ant build xml file is provided, this file has the following targets available:
To build the tiles-example sample application run the following commands from the <spring_home>\samples\tiles-example directory.
build clean (recommended if this is not your first build)
build build
build docs
build warfile
This will create the tiles-example.war file in the <spring_home>\samples\tiles-example\dist directory. This is the file we will use for deploying to Apache Geronimo.
To deploy the sample application we will use the command line option. Run the following command from the <geronimo_home>\bin directory:
deploy --user system --password manager deploy <spring_home>\samples\tiles-example\dist\tiles-example.war
In order to use the deployer tool, the Apache Geronimo server has to be running. |
Once the application has been successfully deployed you should see a confirmation message similar to this example.
E:\geronimo-1.0-Tomcat.06-03-06\bin>deploy --user system --password manager deploy
\spring-framework-1.2.7\samples\tiles-example\dist\tiles-example.war
Deployed org/springframework/samples/tiles @
http://hcunico:8080/tiles
When you deploy an application from the command line using the deployer tool you will receive as a part of the confirmation message the URL (context root) for testing the application.
Open a web browser and access the following URL:
This sample application provides the most basic skeleton for a Web application using Spring. It shows the necessary web.xml and Spring-specific configuration (in the WEB-INF directory) for a complete application. It also provides a build script and simple structure for your application. Refer to the application's readme.txt for further details.
For this sample application you will not need to provide a Geronimo specific deployment plan given that it is a very simple application.
To build the application an Ant build xml file is provided, this file has the following targets available:
Before you build the application you will need to copy some .jar files to the <spring_home>\samples\webapp-minimal\lib directory, the files you need to copy are:
To build the WebApp-minimal sample application run the following commands from the <spring_home>\samples\webapp-minimal directory.
ant clean (recommended if this is not your first build)
ant build
ant warfile
This will create the minimal.war file in the <spring_home>\samples\webapp-minimal\dist directory. This is the file we will use for deploying to Apache Geronimo.
To deploy the sample application we will use the command line option. Run the following command from the <geronimo_home>\bin directory:
deploy --user system --password manager deploy <spring_home>\samples\webapp-minimal\dist\minimal.war
In order to use the deployer tool, the Apache Geronimo server has to be running. |
Once the application has been successfully deployed you should see a confirmation message similar to this example.
E:\geronimo-1.0\bin>deploy --user system --password manager deploy \spring-framework-1.2.7\samples\webapp-minimal\dist\minimal.war
Deployed minimal @ http://hcunico:8080/minimal
Note that since we did not provided any deployment descriptor, Geronimo is using by default the name of the war file as the configID and context root for deploying this application.
When you deploy an application from the command line using the deployer tool you will receive as a part of the confirmation message the URL (context root) for testing the application.
Open a web browser and access the following URL: