Spring Console Extension
The Spring on WebLogic Server paper described a new console extension that can be downloaded with the Spring on WebLogic kit. Many folks have had trouble getting this working, so I thought I would go over the setup once again and describe some of the gotchas.
Essentially the console extension displays registered spring beans in a table and allows you to call the accessors and mutators. In order to do this the beans needs to be exported via JMX and then registered with the console extension. The extension comes in two pieces, a client piece that gets packaged with your spring application and does the registration, and a server piece that gets packaged with the server and adds the extension page.
The first step in configuration is to add the relevant configuration to your spring applicationContext.xml. The config will look something like this:
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="petclinic:service=clinic" value-ref="clinic"/>
</map>
</property>
<property name="assembler">
<bean class="org.springframework.jmx.export.assembler.InterfaceBasedMBeanInfoAssembler">
<property name="interfaceMappings">
<props>
<prop key="petclinic:service=clinic">org.springframework.samples.petclinic.jdbc.CachingClinic</prop>
</props>
</property>
</bean>
</property>
<property name="listeners">
<list>
<ref local="mediator"/>
</list>
</property>
<property name="autodetect" value="true"/>
<property name="server">
<bean class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jmx/runtime"/>
</bean>
</property>
</bean>
<bean id="mediator" class="com.interface21.wl9.jmx.mediator.Mediator">
<property name="applicationName" value="petclinic"/>
</bean>
The first part of the config identifies which beans you will be exporting, so value-ref should refer to another bean in your config. However note that it is also crucial that the true application name be used for the ObjectName "petclinic:service=clinic" (i.e. the petclinic part). The console extension looks up beans based on special JMX ObjectNames built from the application name, and if these are not in sync you will see no beans.
The same applies to the interface mappings section further down. Note too that you must expose you beans via an interface, you cannot simply export a regular JavaBean. It is this interface that appears in the interfaceMappings section.
Finally the JMX exporter refers to a mediator that listens to events and publishes beans to the console as they are exported to JMX. The mediator section appears at the bottom, and again the applicationName must exactly match your application name, otherwise you will see no beans.
We plan to make the configuration of this much simpler very soon, so stay tuned. You can see the full set of properties for the MBeanExporter here. Likewise you can see the configuration properties for the InterfaceBasedMBeanInfoAssembler here.
Once you have your config sorted, you need to build your application and include the console client extension. Unfortunately there was a bug in earlier builds of this and doubly unfortunately the builds of client and server pieces need to match. So I include both the server jar and client jar libraries here. I have verified these with WebLogic Server 9.1 and Spring 2.0-m5. They should work fine with earlier versions of Spring. The extension has been designed so that the version of Sping used by the server piece does not need to match that used by the client piece. You will however need to bundle the appropriate Spring jars with your application also.
Finnaly you need to configure the server extension, this simply involves dropping the server jar into the console-ext directory of your WebLogic Server configuration. Start the server run the app and you should be good to go. The extension appears as an extra tab called "Spring Management Objects" under the deployment entry for your application in the console.
Gotchas - there are a bunch of things that can go wrong here:
- If the tab does not appear then you likely have not configured the server extension correctly. The other possibility is that you are using autodeployment. autodeployment does not work with the console extension, you must use regular deployment.
- If you get the tab but no managed objects then most likely your application name does not match the one you configured. Also check that you are using the correct versions of the console extension, both server and client shown above.
- Clustering is not really supported at present - the beans are exported to the JMX server of the server on which they reside. The console must therefore also be running on this server. Its probably possible to use WebLogic Server's federated JMX server to look up beans remotely, but I have not tried that as yet.