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

Provide a non-@Component-sterotype annotation that tags a bean class to be scanned fro @Bean annotations [SPR-5795] #10465

Closed
spring-projects-issues opened this issue May 29, 2009 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Mark Kralj-Taylor opened SPR-5795 and commented

Spring component-scanning discovers @Component stereotype annotated classes.
One thing that Spring does for these 'components' is to scan the class for @Bean annotations.

We have a use-case where we want a bean's class to be scanned for @Bean annotations, but without the bean being @Component stereotype annotated.

  • We want Spring to scan for @Bean annotations in the class for some beans configured in explicitly (esp in XML config) to Spring.

Please can spring provide a new annotation that:

  • marks a class so Spring scans it for @Bean annotations, when it is used as a Spring bean
  • without making the class eligible for component-scanning

Our specific use case is where Spring beans have internal components that Spring needs to know about so they can be detected by JMX exporting.


Affects: 3.0 M3

Referenced from: commits b8c1130

@spring-projects-issues
Copy link
Collaborator Author

Mark Kralj-Taylor commented

Expect it makes sense for the new annotation to ask Spring to scan bean class for the other new annotations as well as @Bean given in Spring 3 docs (@Value etc)

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/ch02s04.html#new-java-configuration

@spring-projects-issues
Copy link
Collaborator Author

Mark Kralj-Taylor commented

Would it make sense for context:annotation-config/ to turn on Spring respecting @Bean, @Value etc annotations in beans?

In this case Spring would only check the beans it knows about (that are explicitly configured), there woudl be no calsspath scanning to pick-up beans.

We see component scanning (<context:component-scan ...>) to 'pick-up' beans as more 'magic' than Spring respecting annotations on beans that are explicitly provided to Spring (e.g. in Spring XML config).

If respecting @Bean and @Value etc is too much functionality (magic) for context:annotation-config/ to turn on then perhaps it could be attribute option of an option of context:annotation-config/ or a different annotation.

@spring-projects-issues
Copy link
Collaborator Author

Juergen Hoeller commented

As previously discussed, ConfigurationClassPostProcessor is automatically registered by context:annotation-config/ already. We are now also introspecting methods of registered bean classes, detecting @Bean methods there even if the containing class is not annotated with an @Configuration or @Component stereotype. This isn't too expensive since we have to parse the metadata for such bean classes anyway; introspecting methods on the bean class is quite fast then since we parsed the entire class anyway.

Juergen

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 3.0 RC1 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants