AlertsJmxConfiguration implements DynamicMBean { @Override public Object getAttribute(String attrName) throws AttributeNotFoundException, MBeanException, ReflectionException { Assert.notNull(attrName, "attrName must not be null"); AlertInfo alert = getAlert(attrName); if (StringUtils.endsWith(attrName, ENABLE_SUFFIX)) { return alert.isEnabled(); } else if (StringUtils.endsWith(attrName, LIMIT_SUFFIX)) { return String.valueOf(alert.getLimit()); } else { throw new IllegalStateException("unsupported attribute name '" + attrName + "'"); } } @Autowired  AlertsJmxConfiguration(AbstractAlertsConfiguration configuration); @Override MBeanInfo getMBeanInfo(); @Override Object getAttribute(String attrName); @Override void setAttribute(Attribute attribute); @Override AttributeList getAttributes(String[] strings); @Override AttributeList setAttributes(AttributeList objects); @Override Object invoke(String s, Object[] objects, String[] strings);  }
@Test public void testGetAttribute() throws MBeanException, AttributeNotFoundException, ReflectionException { Object attribute = jmx.getAttribute("ID.enabled"); assertThat(attribute, notNullValue()); assertThat(attribute.toString(), is("true")); attribute = jmx.getAttribute("ID.limit"); assertThat(attribute, notNullValue()); assertThat(attribute.toString(), is("11")); try { jmx.getAttribute("something"); fail("there is no attribute with specified key"); } catch (AttributeNotFoundException ex) { } }