JBoss.org Community Documentation
This tutorial is similar to the "service" tutorial which shows how to use Service POJOs in JBoss. In this tutorial we will use deployment descriptors instead of annotations to configure the services.
Take a look at org.jboss.tutorial.service_deployment_descriptor.bean.ServiceOne
and the corresponding deployment
descriptor META-INF/jboss.xml
. The <service>
tag defines it as a
singleton service in JBoss. It implements org.jboss.tutorial.service_deployment_descriptor.bean.ServiceOneRemote
and org.jboss.tutorial.service_deployment_descriptor.bean.ServiceOneLocal
using the <business-remote>
and <business-local>
tags.
ServiceOne also implements org.jboss.tutorial.service_deployment_descriptor.bean.ServiceOneManagement
identified through the <management>
tag. JBoss will inspect this interface, and create and
install an MBean implementing the attributes and operations defined in the interface. The MBean will work on the same
singleton bean instance as the remote and local interfaces.
The META-INF/jboss.xml
also shows that the default ObjectName of the service can be overriden
using the <object-name>
tag:
<service> <ejb-name>ServiceOne</ejb-name> <ejb-class>org.jboss.tutorial.service_deployment_descriptor.bean.ServiceOne</ejb-class> <business-local>org.jboss.tutorial.service_deployment_descriptor.bean.ServiceOneLocal</business-local> <business-remote>org.jboss.tutorial.service_deployment_descriptor.bean.ServiceOneRemote</business-remote> <object-name>tutorial:service=serviceOne</object-name> <management>org.jboss.tutorial.service_deployment_descriptor.bean.ServiceOneManagement</management> <jndi-name>serviceOne/remote</jndi-name> <local-jndi-name>serviceOne/local</local-jndi-name> </service>
Take a look at org.jboss.tutorial.service_deployment_descriptor.bean.ServiceThree
and
org.jboss.tutorial.service_deployment_descriptor.bean.ServiceTwo
where we use the @Depends
annotation to add dependencies between services.
For a detailed explanation of @Depends in @Service, take a look at our "service" tutorial.
To build and run the example, make sure you have installed JBoss 5.x. See the Section 1.1, “JBoss Application Server 5.x” for details.
From the command prompt, move to the "service_deployment_descriptor" folder under the Section 1.3, “Set the EJB3_TUTORIAL_HOME”
Make sure the "default" server configuration of JBossAS-5.x is running
$ ant $ ant run run: [java] attribute value for singleton obtained via JMX is what we set via remote interface: 100 [java] Hello from service One [java] Hello from service Two
$ mvn clean install -PRunSingleTutorial
On the server side when the application is deployed, you will notice these logs:
17:37:17,869 INFO [STDOUT] ServiceOne - Started ... 17:37:17,910 INFO [STDOUT] ServiceTwo - Started ... 17:37:17,949 INFO [STDOUT] ServiceThree - Started
Notice that the order is maintained because of the dependencies we have configured on the @Service.