[cdi-dev] [JBoss JIRA] (CDI-377) automatic JSR-330 annotation processing problematic
Colin Decker (JIRA)
jira-events at lists.jboss.org
Thu Sep 12 19:12:03 EDT 2013
[ https://issues.jboss.org/browse/CDI-377?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12804030#comment-12804030 ]
Colin Decker commented on CDI-377:
I think this issue should be reopened.
CDI 1.1's handling of JSR-330 annotations in jar files on the classpath is overly eager and causes problems for libraries that simply want to include JSR-330 annotations to make it easy to use those classes with JSR-330 compatible frameworks. I feel that CDI 1.1 is effectively violating JSR-330 by assuming the presence of its standard annotations (for example, @Singleton) means not that a class *can* be injected but that it *must* be injected.
This has caused problems for users of Guava, as indicated in the linked Guava issue. We tried to help those users by adding a beans.xml to the Guava jar with bean-discovery-mode=none, but that breaks CDI 1.0 users because the presence of beans.xml in the jar causes CDI 1.0 to scan the jar where it didn't before, while the bean-discovery-mode, being new in CDI 1.1, is ignored. This is a frustrating situation as it seems to mean that Guava has to choose between working out of the box for CDI 1.0, working out of the box for CDI 1.1, or removing the JSR-330 annotations entirely, an inconvenience to users of other JSR-330 frameworks.
In short, CDI should respect the fact that JSR-330 annotations are a shared standard and should not handle them in ways that restrict their use in libraries. They should never, on their own, be treated a signal that a class must be instantiated and injected. At a minimum, requiring a beans.xml file in the jar as an explicit acknowledgement that the jar wants be handled according to CDI's specification, as CDI 1.0 does, seems reasonable.
> automatic JSR-330 annotation processing problematic
> Key: CDI-377
> URL: https://issues.jboss.org/browse/CDI-377
> Project: CDI Specification Issues
> Issue Type: Bug
> Components: Java EE integration
> Affects Versions: 1.1.PFD
> Environment: glassfish-4
> Reporter: Reuben Pasquini
> Labels: CDI, guava, guice
> Fix For: 1.1.PFD
> The jsr-330 dependency injection annotations (javax.inject.*) find use in javase environments using IOC packages like guice.
> Adding a dependency on a jar that uses guice or whatever in a javase environment
> to a war deployed to a jee7 container
> results in CDI processing annotated classes intended for
> app-managed injection. See this ticket filed with guava for a concrete example:
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the cdi-dev