Can Spring understand that @Inject replaces Weld as an implementation of JSR-299?

I noticed from several web pages that Spring 3.0 seems to support @Inject from JSR-330. Since we really would like to use the JSR-299 syntax for dependency injection in our libraries for both web applications and standalone applications and have Weld alternatives, it would be nice if Spring could do this.

Being new to Spring, I tried to download the Spring Framework distribution and put all the jars in the Eclipse build path. No Inject annotations, so my existing test project using Weld did not compile.

Can this be done with Spring? What do I need to do to run it?

(I know that in the end it will also support Guice. It is only in SVN, and if there is an official Spring release that can, it would be better.)


It can be done. The JSR-330 box must be loaded separately, and cglib must be used to parse the manually written @Configuration classes, as well as to log the community logging.

The biggest difference from Weld is that the wiring must be written by hand, and not magically found (a little more cumbersome, but can create more reliable applications), plus startup time is much shorter. I'm still new to Spring - is there a way for @Configuration classes to open automatically?

+5
source share
2 answers

Spring 3.0.x :

JSR 330 @ Spring @. . @Inject Spring @ @Autowire, , , . , JAR 330 JAR .

, DI @Inject, javax.inject , Spring . JSR-330 Google Code.

+2

javax.inject Spring 3, , .

AutowiredAnnotationBeanPostProcessor, , javax.inject.Inject , . .

JAR JSR-330 (, JavaEE 6 SDK).

+2

All Articles