0

I have an issue concerning a jar declaring CDI annotated beans, and used both in a spring context and an EE6 context.

This jar, say service.jar, contains classes that are annotated with qualifiers (@Qualifier, allows you to declare your own annotations such as @DataAccessObject in order to identify your beans), and has private members annotated with @Inject.

It's compiled with maven, and it's dependency to javax.javaee-api is declared as provided, because these classes are only needed when deployed within an EE6 context.

Though, there's something that I don't understand. In this service.jar, once compiled, and whether I deploy it in an EE6 context or not, the bytecode references classes such as javax.inject.@Inject.

So why my spring application - which has no javax.javaee-api jar in its classpath - is able to load its configuration correctly and run ? I was even more confused when I learned that spring provides support for @Inject (JSR 330) annotation.

Can anyone enlighten me on that ?

Thanks.

LaurentG
  • 11,128
  • 9
  • 51
  • 66
Localolhst
  • 41
  • 5
  • There is a long history to this, mostly political, this sheds some light, although not completely. http://stackoverflow.com/questions/7238407/will-spring-support-cdi – rdcrng Aug 16 '13 at 12:21

1 Answers1

0

You must not confuse DI (JSR330) and CDI (JSR299). CDI includes DI. All those javax.inject Annotations belong to DI and are supported by many frameworks (spring and guice for example).

If you strictly reduce your jar dependencies to JSR330 (no need to switch Java EE deps for deployment), you will be able to use any of the supporting frameworks.

Checkout this example: http://www.mkyong.com/spring3/spring-3-and-jsr-330-inject-and-named-example/

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Jan Galinski
  • 11,768
  • 8
  • 54
  • 77
  • I wasn't aware of JSR299, thanks. Though, I'm still confused about how can my spring application load some jar which contains `javax.inject` references in it's bytecode, while there's nothing to fill this dependency in the classpath. – Localolhst Aug 18 '13 at 08:54