Skip to content
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

Preserve custom annotations present on @Bean methods for interrogation during bean post processing [SPR-5611] #10282

Closed
spring-projects-issues opened this issue Mar 25, 2009 · 1 comment

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Mar 25, 2009

Ittay Dror opened SPR-5611 and commented

With Spring using more and more annotations, it would be good if the bean definitions allow registering custom annotations for use with Bean/Factory post processors.

Specifically, in JavaConfig one can annotate a method in a configuration class with @Bean annotation to create a bean from the result of the method. However, it is not possible to add custom annotations on the method so as to process them with a bean post processor.

The use case is for integrating with spring-dm. Specifically, I would like to annotate a "regular" @Bean method with @OsgiService annotation so the bean is published as a service.

NOTE: another approach is to allow me to replace @Bean with @OsgiServiceBean which would do both. The current JavaConfig code is very tightly bound to the internal annotations and it is had to add custom ones (specifically, i can't create a custom annotation and reuse BeanRegistrar since it uses @Bean directly)


Affects: 3.0 M2

Reference URL: http://forum.springframework.org/showthread.php?p=232837#post232837

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Jun 17, 2011

Chris Beams commented

Hi Ittay,

It's been quite a while since entering this issue, and we haven't had additional interest since in preserving custom annotations when processing @Bean methods.

While not impossible, there are a number of reasons why it would be problematic to do so. I'm resolving this as won't fix for now, however keep in mind that there is a workaround that may meet your needs. Since you were planning to employ a BeanPostProcessor anyway, you could:

  • use the beanName provided to the BPP methods to look up the associated BeanDefinition from the enclosing BeanFactory;
  • query that BeanDefinition for its factoryBeanName (the @Configuration bean) and factoryMethodName (the @Bean name);
  • use reflection to get hold of the Method the bean originated from
  • use reflection to interrogate any custom annotations from that method

If this is still relevant to you, I hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant