Autowiring vs instantiating in Spring

后端 未结 2 533
春和景丽
春和景丽 2021-01-22 17:34

I\'ve started to use Spring recently. And I\'m making spring mvc project. So my question is if it\'s preferred to make interfaces and autowire it with particular implementation

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-22 17:37

    It will depend on whether MyService is a bean that holds a state or not. If MyService does not hold state, then you don't need to create new instances and you can let Spring to inject it having the advantages above described

提交回复
热议问题