私は今のところ数か月からSpringを使用していますが、@Autowired
アノテーションを使用した依存性注入には、フィールドに注入するためのセッターも必要だと思いました。
だから、私はそれを次のように使用しています:
@Controller
public class MyController {
@Autowired
MyService injectedService;
public void setMyService(MyService injectedService) {
this.injectedService = injectedService;
}
...
}
しかし、私は今日これを試しました:
@Controller
public class MyController {
@Autowired
MyService injectedService;
...
}
そして驚いたことに、コンパイルエラーも起動時のエラーもありません。アプリケーションは完全に実行されています...
だから私の質問は、@Autowired
アノテーション付きの依存性注入にセッターが必要ですか?
Spring3.1.1を使用しています。