I am a junior engineer on a Java team that uses Spring. We have been coached to Autowired Setters of instance variables rather than Autowiring the actual instance variable. I am slightly confused as to why we do this, what are the advantages of doing this and possible shortfalls of handling dependency management in this way ?
Some observations from me (actually 3 years in Java EE):
Advantages:
Disadvantages:
Personally I prefer instance variable or constructor injections. But this is service dependent. I would not say that using setters is better. It has just different purposes.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments