Tutorial Assignment

Tutorial Assignment

Tutorial Assignment:

This tutorial mainly focuses on setting up Spring 2.0 Framework in Oracle JDeveloper 10.1.3.1 using the iBatis framework for connecting to back end. Spring is an open source framework which can be used for developing enterprise applications. This tutorial mainly explains the various steps involved in creating a spring application using JDeveloper. Also it explains how to import and set the spring libraries in JDeveloper, various features in JDeveloper that supports application development using Spring framework and various files that one has to configure for setting up Spring in JDeveloper.

The tutorial makes use of JPetStore application as example provided by the spring framework website.

Before starting the tutorial, we have to install Oracle JDeveloper 10.1.3.1 and Spring 2.0 framework.

Once these are done, open JDeveloper to create a new application with name as Spring. Since we are making se of the JPetStore sample application provided along with the spring framework download, we give the directory name as samples located inside Spring framework folder.

The project name is given as JPetStore and directory name same as one given above while creating the application.

Also the web interface is created as shown below. The war sub directory is added to the project in order to serve as the web interface.

In order to build the sample application, we can use the Ant Tasks in JDeveloper. Running the Ant script using the build.xml creates a new directory with all the libraries needed to distribute and compile the code.

The screenshot given below shows that build was successful. The Apache Ant log gives the details of build.

Any third party libraries have to be added separately in JDeveloper. For adding we have to go to Project Properties and click on Libraries node. Now click on Add Jar/Directory button to add all the Spring jar files from JPetStore sample application. After selecting all the jar files, click Add to include all these files.

Also we have to add a couple of generic libraries into our project as shown below. We have to add libraries through the Project Properties window. The screenshot below shows this step.

Developer provides lot of features for editing XML files which are very important for using Spring framework. For using this feature in JDeveloper, we have to register the xml schemas provided in the sample application. Go to Tools -> Preferences Menu in order to add the xml schemas. The screenshot given bellows shows this step.

The screenshot below shows the applicationcontext.xml file of Spring framework. For every java bean that we create, the mapping has to be provided in this file. It is similar to the strutsconfig.xml file in Struts framework. The mapping between the bean name and the Data Access Object (DAO) is shown in the screenshot below.

This is the struts-config.xml file if we are using the struts framework above the spring architecture. The action forward mappings are done in this file.

The screenshot below shows a jsp page developed for JPetStore application. JDeveloper allows split windows which allow the developers to view both the design and code windows as split screens. This feature is shown in the screen shot given below.

The screenshot shown below gives a simple POJO used for the application. It’s nothing but a Plain Old Java Object. The class shown below is a java bean with the getter and setter methods for the fields in jsp page.

The business logic is put in the controller class. Below shown is an ActionController class. Also it has a member variable PetStoreFacade which is nothing but a primary business interface.

The PetStoreFacade interface class will look like the one shown below in the screenshot.

The screenshot below shows the PetStoreImpl class. This class implements the PetStoreFacade interface. This class sets the values of Data Access Objects (DAO).

The screenshot given below shows the Data Access Object (DAO) interface class that was called by the façade implementation class shown above.

The screenshot given below shows the Data Access Object (DAO) implementation class. It contains all the method calls to the database.

Here we are using the iBatis framework to connect to the back end. So we have to configure the sql-map-config.xml file in order to do the mappings of the java bean form variables to that of the columns in table. This screenshot given below shows all the xml maps used for the above said mapping. We just need to specify the file names in this.

The screenshot given below shows one of the iBatis sql map. In this xml we specify the stored procedure, input parameters and the name of the java bean and its member variables to which the table columns or result sets are to be mapped.

Once all the libraries are added and all settings and above configurations required for implementing the Spring framework in JDeveloper are done, we can compile the application. The screenshot shows that the application was compiled and run successfully.

The screen shot given below shows the index page of the JPetStore sample application run in JDeveloper OC4J sever after setting up the Spring framework.

Thus the tutorial given above explains various steps involved in setting up the Spring framework in Oracle JDeveloper. It explains the steps involved in configuring and adding the Spring libraries into the application. Also it gives a brief idea of the various files in the application based on Spring framework, along with their interconnections and those files and mappings that a developer has to take care while developing an application based on Spring 2.0. This can serve as a reference to anyone trying to develop a web application in JDeveloper based on the Spring 2.0 framework.

Submitted by Jaidev Manghat 11/2006