This documentation is for WSO2 Application Server version 5.0.0. View documentation for the latest release.

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 15 Next »

Developing Spring Services

To develop a simple Spring service, you have to provide a Spring context .xml file, which has a .jar file that contains the bean classes specified in it. Given below is an example of a simple Spring context .xml file specifying a particular bean with an ID and a class name which can be found in the .jar file.

<?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
 <beans>
    <bean id="SimpleEchoBean">org.wso2.test.EchoBean"></bean>
 </beans>

The Echo Bean for this example is shown below. It can contain any type of service implementation.

package org.wso2.test;
 /*** Example EchoBean***/

 public class EchoBean {
   public String echoString(String input) {
     return input;
   }

   public int echoInt(int input) {
     return input;
   }
}

Deploying Spring Services

WSO2 provides capability to deploy Spring beans as a Web service and this capability is facilitated by the following feature:

Name: Spring Service Hosting Feature
Identifier: org.wso2.carbon.springservices.feature.group

If Spring service deployment capability is not included in your product by default, you can add it by installing the above feature using the instructions given in section Feature Management. 

Follow the instructions below to deploy a Spring Service to a running Carbon instance.

1. Log on to the product's Management Console and select "Service -> Add -> Spring Service."

2. In the "Add Spring Service" window that appears, specify the relevant files and click "Upload". For example,

Service Hierarchy

Specifying a service hierarchy is optional. It allows you to customize your service endpoint reference. If the business logic of the same service changes over time, you can maintain multiple versions of the service by using service hierarchy at the deployment. For example, consider a service named "SpringTest"

If the service hierarchy is not mentioned, then the service endpoint reference is ../services/SpringTest. With service hierarchy specified, for example as 1.0.0, the endpoint reference is ../services/1.0.0/SpringTest.

Specifying a hierarchy is important if you want to manage services separately.

3. If the files are not faulty, the "Select Beans to Deploy" page appears.

If the beans specified in the spring context .xml file are mentioned in the .jar file, they will be displayed on this page.

4. Select the "Include" check box associated with the the beans you want to expose as Web services and click "Generate."

5. If the generation is successful, a message appears prompting you to refresh the page. Click "OK."

6. Refresh the "Deployed Services" page in your product's Management Console to view the newly added services listed.

If your service implementation depends on any third-party libraries, you can copy them to <PRODUCT_HOME>/repository/components/extensions directory and restart the server to get your service started.

  • No labels