views:

127

answers:

2

I was reading a Wikipedia article about Java EE application servers here:

http://en.wikipedia.org/wiki/Java_Platform,_Enterprise_Edition#Java_EE_5_certified

It says that 2 APIs that Java App Services implement are:

javax.enterprise.inject
javax.enterprise.context

These both relate to application context and dependency injection JSR-299. I had never heard of these APIs before. Does Spring implement these APIs? Would it matter to anyone if they did?

+2  A: 

Spring does support JSR-330's @Inject - it can be used in place of @Autowired (except that it doesn't have a required property).

You also need to have the JSR 330 jar on the classpath.

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html#beans-autowired-annotation

Ash Kim
More details on using JSR-330 support in Spring can be found here: http://stackoverflow.com/questions/3055724/can-spring-understand-inject-replacing-weld-as-a-jsr-299-implementation/3055829#3055829
Ophidian
+3  A: 
  • JSR-330 defines a set of annotations (javax.inject) that are to be used across different dependency injection frameworks. The specification was lead by Rod Johnson (from Spring), and Bob Lea from (Google Guice)
  • (partly) because of the spec leads, spring and guice support this set of annotations

This is the part of JavaEE that is used by spring.

The same set is used by JSR-299, which is lead by Gavin King from JBoss. However, JSR-299 (also known as CDI) uses javax.enterprise.inejct/context and is a whole new dependency-injection framework. It is based on ideas of spring, guice and seam, but is specified formally as a JSR and aims at covering many corner cases as well as smooth integration with other JavaEE parts.

JSR-299 defines both an API and SPI so that concrete implementations can be developed. Current implementations are JBoss Weld, Apache OpenWebBeans and Resin CanDI.

So, to answer your question - there is no direct relation between javax.enterprise.inject and spring.

Bozho
So is JSR-299 an API (like JPA or JTA) or an actual implementation? If an API, do you know if Spring will implement it eventually?
HDave
it's a specification - both API and SPI. No, spring won't implement it in my opinion. See my update.
Bozho