Spring @Autowired usage

后端 未结 9 832
长发绾君心
长发绾君心 2020-12-04 04:51

What are the pros and cons of using @Autowired in a class that will be wired up by Spring?

Just to clarify, I\'m talking specifically about the

9条回答
  •  孤街浪徒
    2020-12-04 05:16

    Here are some of experience
    Pros

    • Makes easier to configure because we can just use @Autowire annotation
    • Don't want to use setter methods , so class will be more clean

    Cons

    • Tightly couple to xml file even though we are using DI
    • Hard to find implementation (But if you your using good ides like intellij sure you can get rid of this)

    As of my personal experiences I didn't use @AutoWire annotation that much but in test cases.

提交回复
热议问题