哪个更正确?
这个(在方法上带有@Autowired 注释)?
@Controller
public class MyController
{
private MyDao myDao;
@Autowired
public MyController(MyDao myDao)
{
this.myDao = myDao;
}
这个(在属性上带有@Autowired 注释)?
@Controller
public class MyController
{
@Autowired
private MyDao myDao;
public MyController(MyDao myDao)
{
this.myDao = myDao;
}
@Autowired 注释应该去哪里?