-
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
JSR-330 support for component detection is inconsistent [SPR-6465] #11131
Comments
Juergen Hoeller commented The problem here is that scope annotations are not consistently used in JSR-330: The default prototype scope does not have a corresponding annotation by design. So for that kind of component, we can't rely on a scope annotation for detection purposes. In addition to that inconsistency, we are not detecting Spring-style components based on scope annotations either. We'd have to do both or none. Admittedly, we are applying a special meaning to JSR-330's Our recommendation is to use Spring-style stereotypes anyway and just add JSR-330 injection and qualifier annotations for the injection points. The same applies to scoping: We recommend Spring-style scoping over JSR-330 scoping, in particular with respect to the default singleton scope in Spring that differs from the default prototype scope in JSR-330. Juergen |
Eberhard Wolff commented Jürgen, I see your point. I guess my main problem is that I am surprised that a class that is annotated with |
Alexandre Navarro commented Juergen, I'm not sure I understand what you said. |
Alexandre Navarro commented I confirmed the bug, instantion of a class works well with |
Juergen Hoeller commented Some related news: Java EE 6 went final a couple of days ago. It includes a "javax.annotation.ManagedBean" annotation now, which is exactly what we need for our purposes here: It is defined as supporting So as of Spring 3.0 GA (scheduled for tomorrow), we support However, "javax.annotation.ManagedBean" is a bit hard to obtain, since it is part of JSR-250 v1.1 but actually defined in a separate "Managed Beans 1.0" specification which is part of JSR-316 (the Java EE 6 umbrella JSR). The annotation type is available on the classpath of a Java EE 6 server, in any case; let's see whether it'll be available as a standalone jar as well (before Java SE 7, that is). So conceptually, I'd recommend using At this point, detecting components based on the plain presence of a scope annotation isn't being considered for Spring 3.0.x anymore. Note that neither JSR-330 nor any other Java EE 6 JSR covers detection based on scope annotations either; it would be just as custom as our use of Juergen |
Alexandre Navarro commented I asked the upload javax.annotation-1.1 in the maven repository jar of https://glassfish.dev.java.net/issues/show_bug.cgi?id=11309. Thanks if you are interested to vote for it. |
Alexandre Navarro commented Just for information, the jar with <dependency> (weird to have a glassfish in groupId). Alexandre |
Alexandre Navarro commented
|
Eric Sirianni commented There is also a friendlier (i.e. Apache) licensed implementation of the Java EE6 annotations available from geronimo. http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-annotation_1.1_spec/ |
Eberhard Wolff opened SPR-6465 and commented
If I annotate a class using
@Named
it is instantiated by context:component-scan . However,@Named
is just an example for an@Qualifier
annotated Annotation. The JavaDoc for@Qualifier
states that the specification only covers using such annotations on fields and methods, classes are optional. So even though this behavior does not contradict the specification it is not required either.But if
@Named
means that a class is implemented by context:component-scan the same should work for my own@Qualifier
annotated Annotation as well. That is not the case.Also a class annotated with
@Singleton
is not instantiated by context:component-scan and probably other Annotations that are marked with@Scope
work the same way. I think it would be more logical to have these annotations work with context:component-scan than the@Named
annotation as they clearly belong to implementation classes which@Named
does not. But again this is not covered by the spec.Affects: 3.0 RC2
1 votes, 3 watchers
The text was updated successfully, but these errors were encountered: