OK, so you would create your MBean service class as described in the documentation links
in my first post.
- create an interface for your MBean that extends extends org.jboss.system.ServiceMBean
-create your MBean class that extends extends org.jboss.system.ServiceMBeanSupport and
implements your interface from step one
-put all the logic/methods that want to use in this class
-load your MBean service using a *-service.xml file, which specifies the NAME of the
service you have created. This file can either be right under the deploy directory or in
the META-INF dir inside your .sar application. The service should then show up in your
jmx console under this name. Now you can inject the service using the code that you
quoted.
For example, here is the code in the jboss-portal.sar/META-INF/jboss-service.xml file that
loads the UserModule portlet as a service in your example
| <mbean>
| code="org.jboss.portal.identity.db.UserModuleImpl"
| name="portal:service=Module,type=User"
| ...
| </mbean>
|
The code= is the name of the class, so you would use your classe's fully qualified
name.
The name= is the name you want to call your service. I'm not sure if you have to
start the name with portal: for it to work with a portlet, but you can try with a
different name if you want.
The basic structure of the name should be:
{app-name]:service={somename},type={somename}
So your descriptor would look something like:
| <mbean>
| code="org.mypackage.DAOClass"
| name="portal:service:Module,type=DAOAccess"
| </mbean>
|
Then you can inject the service in your portlet with this code in your jboss-portlet.xml
file
| <portlet-app>
| <service-name>DAOAccessModule</service-name>
| <service-class>org.mypackage.DAOClass</service-class>
| <service-ref>:service-Module,type=DAOAccess</service-ref>
| </portlet-app>
|
(if you use a name other than portal for start of your service name, you should include it
in the servive-ref, not sure about if that works or not)
So, the ref and class are the same as set in the service.xml, the name you will use in
your portlet to get the service from the context
| DAOClass dao = (DAOClass)
getPortletContext().getAttribute("DAOAccessModule");
| dao.getConection() ....
|
I should mention that I have never done this yet, I have only created a service, I
haven't injected it in a portlet before. But this is how the docs say to do it.
If you use the ejb3 method to create your MBean you simply create a class and add the
@Service annotation with the name of your service (portal:Service=Module,type=DAOAccess)
and the @Management annotation with the interface describing the methods, etc that you
want to expose in the service in the jmx-console. That is explained in the link in my
first post. Then you inject the service the same way as in your example code.
I hope this helps.
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3968809#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...