The documentation contains following paragraph.
"As with @Autowired, it is possible to use @Inject at the class-level, field-level, method-level and constructor-argument level."
If I have not a mistake, I know @Inject annotation can be used field-level, method-level and constructor-argument level, can not be used class-level.
Inject Annotation Source Code :
@Target({ METHOD, CONSTRUCTOR, FIELD })
@Retention(RUNTIME)
@Documented
public @interface Inject {}
Is it true?
For me, they are almost equivalent, @Inject
is part of the CDI introduced since Java EE 6 and @Autowired
part of the Spring framework.
The @Autowired
interface looks to have the same target as @Inject:
@Target(value={CONSTRUCTOR,FIELD,METHOD})
@Retention(value=RUNTIME)
@Documented
public @interface Autowired
I think it is a small error in Spring documentation chapter 5.11.1 because I never seen any @Autowired
annotation on a class level.
This link shows the difference and limitation of each approach.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With