Annotations ignored by Spring
Maybe I'm doing something wrong but, I can't find a way to get the annotations to be read by Spring for my managed Beans.
Code:
ManagedResource(description = "Configurable Data Service Factory allows REST client swapping")
public class DataServiceFactory implements IDataServiceFactory, DataServiceFactoryMBean {
(There is an 'at' sign on the MangedResource but, the forum code was blocking it as a url?)
Code:
<context:mbean-export default-domain="BeerCode" />
<bean id="dataClientFactory" class="com.willcode4beer.rest.client.DataServiceFactory">
<description>Configurable Data Client Factory</description>
<property name="httpClient">
<bean class="com.willcode4beer.rest.client.HttpDataClient" />
</property>
<property name="mockClient" ref="mockDataClient" />
</bean>
When I pull up jconsole, the bean does show up under the name "BeerCode" but, the description is the default instead of what is defined in the annotation. Setting objectName also gets ignored.
Am I missing something?
Specify "assembler" and "attributeSource"
In the Spring XML configuration file, you need to specify the MetadataMBeanInfoAssembler and associate it with a specified attributeSource that uses either Apache Commons Attributes or Java 5/6 Annotations.
Good coverage of using these is available in section 20.3 of the the Spring 2.5 Reference Manual. Because you're using @ManagedResource, it appears that you are using Java annotations, so your Spring XML would look something like that shown in the XML snippets shown in the Reference Manual under sections 20.3.3 and 20.3.5.
You can find examples of the annotations being used in the blog entry Using Spring Metadata MBean Exporting for Greater Descriptive Detail.