-
Notifications
You must be signed in to change notification settings - Fork 38.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MBeanExporter.setExcludedBeans does not work properly on FactoryBeans [SPR-5926] #10595
Comments
Jeffrey Sinclair commented I've investigated this a little further to provide a bit more context. The problem here is with FactoryBeans and the way the MBeanExporter does auto-detection. Take the following example (where CustomerFactory implements FactoryBean):
The MBeanExporter does the auto detection in afterPropertiesSet(). At this time the customer bean is not available, only the bean factory definition which Spring internally creates a bean name of &customer for. Once the customer bean is created, &customer will no longer exist. Hence if the MBeanExporter is before a factory bean, the exclude needs to prefix the bean id with a & for the exclude to work. If you reverse the ordering of the above beans, the excludedBeans property works as expected. The auto dection logic needs to be done after all beans are created or somehow take the above situation into account. |
Dan Carwin commented Customer requests confirmation that this fix is still on target for RC1. Please confirm/correct. Thanks, Dan Carwin. |
Juergen Hoeller commented This should be fixed in 3.0 RC1, with specified excluded names matched against unprefixed FactoryBean names as well (when applicable). Juergen |
Jeffrey Sinclair commented Juergen, I can confirm that the fix put in place does fix the original issue this JIRA was for, however there is still a fundamental ordering issue here causing an inconsistency. I can do the following to ensure the customer bean is excluded thanks to this fix:
However if I remove the excludedBeans property the customer is not included because the customer bean has yet to be created. I have to ensure my exporter is defined after the customer bean. Personally I don't like relying on this kind of ordering since it is very fragile, especially when dealing with multiple files. Would you consider this a bug? Would a BeanPostProcessor (perhaps one implementing InstantiationAware) be more suitable for this logic, i.e. also support lazily exporting beans as they are created? Jeff |
Juergen Hoeller commented Jeff, the ordering issue has been sorted out for 3.0 GA now. Feel free to give the latest snapshot (503) a try: http://static.springsource.org/downloads/nightly/snapshot-download.php?project=SPR Juergen |
Celal Ziftci opened SPR-5926 and commented
Inside the MBeanExporter.autodetect(AutodetectCallback) method, there is a check as follows:
<code>
String[] beanNames = this.beanFactory.getBeanNamesForType(Object.class, true, this.allowEagerInit);
...
if (!isExcluded(beanName)) {
...
}
</code>
Here, the bean names for the factory beans are returned with a ampersand in front (like &someBean), and when the MBeanExporter is used in Spring config with excludedBeans set, one has to use smth like this to get the factoryBean created beans excluded:
<code>
<bean class="org.springframework.jmx.MBeanExporter">
<property name="excludedBeans" value="&someBean" />
</bean>
</code>
So all in all, the framework should know how to handle factory beans and the beans created via them.
Referenced from: commits 566eeba
The text was updated successfully, but these errors were encountered: