Renaud Bruyeron opened SPR-1733 and commented
MBeanServerConnectionFactoryBean.destroy() throws an exception in the following case:
- the connectOnStartup is set to false
- the MBeanServerConnection has not been used yet
- the remote MBeanServer is not available
The reason is that connector.close() will cause the JMXConnectorLazyInitTargetSource to attempt a connection, which might fail.
The fix for this particular case is trivial: add an instance boolean field to keep track of the connection state, and set it to true only during connect() or in the JMXConnectorLazyInitTargetSource. Then change the destroy() method to do this:
if ( connected )
this.connector.close();
The larger question is wether destroy() should throw any JMX exception at all, since this might prevent the BeanFactory from shutting down completely.
Affects: 1.2.6