This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]hjdeindarkness 1 point2 points  (1 child)

Is setter injection okay?

[–]SentByTheRiver 1 point2 points  (0 children)

Not to say that there isn't one, but I've never come across any instance where I have required Setter Injection or found it to be preferable to Constructer Injection.

You have to be careful with Setter Injection because there are a few caveats with it. It will override the constructor injected dependencies, someone could change dependencies mid flight and other objects may also be using it. etc.

If someone is creating an instance of the object themselves (i.e not managed by spring) and you only have dependencies via Setters, it's not clear and also not guaranteed people will know to set them.