Home > Net >  Do we have to write setter method to use @Inject annotation?
Do we have to write setter method to use @Inject annotation?

Time:10-14

is it mandatory to write a setter function when we use @Inject annotation

CodePudding user response:

Nope. It is not mandatory. Reflection is used to set the value.

See this and this for more info.

CodePudding user response:

No, we don,t have to write the setter method for @Inject, it is same annotation as the @Autowired.

@Inject is part of a Java technology called CDI that defines a standard for dependency injection similar to Spring. In a Spring application, the two annotations works the same way as Spring has decided to support some JSR-299 annotations in addition to their own.

@Inject can be injected the reference to the implementation of the Provider interface, which allows injecting the deferred references.

  • Related