4 Replies Latest reply on Oct 24, 2003 12:28 PM by David Ward

    MBean attributes

    twutort Newbie

      I need to have a startup class (like in weblogic) for my system. I've been told and read some articles that say you need to create a service MBean. I found some examples but none of those show how to pass an argument into the MBean. Can I declare an attribute in the xml file that defines the bean and read it in to the MBean? If so, what is the syntax for reading the attributes in the bean?


        • 1. Re: MBean attributes
          Adrian Brock Master

          There are plenty of examples in the jboss
          distribution. The service configurator automatically
          applies them to your mbean.



          • 2. Re: MBean attributes
            twutort Newbie

            Is there any way you can create it like a weblogic startup class? Meaning you can pass in arguments from a property file, in this case an XML file?

            • 3. Re: MBean attributes
              Adrian Brock Master

              I don't know what you mean,
              you can pass properties, see the sql properties
              passed to the jdbc2 persistence manager
              in jbossmq-serivce.xml


              • 4. Re: MBean attributes
                David Ward Newbie

                You don't need to use MBeans. In the Servlet 2.3 spec, ServletContextListeners were introduced. Implement one of those and enter it an a war's web.xml file. Then add this war file to your ear that also contains your ejb-jar files (if you need more than just a web app). Then, you can trigger startup from the contextInitialized() method and shutdown on the contextDestroyed() method. This is a standard J2EE way of doing startup/shutdown hooks of J2EE applications, and is therefore appserver agnostic.

                Oh yeah. If you can't use Servlet 2.3 spec, you can use a similar (though not as elegant) mechanism in 2.2. Write a Serlvet instead of a ServletContextListener, and do your startup/shutdown code in the init()/destroy() methods, respectively. Then in web.xml, register the servlet *and be sure to add* a <load-on-startup>1</load-on-startup> element (the # doesn't really matter unless you want to order it with other servlets).

                To configure it, you can put a properties file or xml file in your jar next to the ServletContextListener (or Servlet) and load in the config using yourClass.getResource().