Spring

@Autowired

https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-autowired-annotation

As of Spring Framework 4.3, an @Autowired annotation on such a constructor is no longer necessary if the target bean defines only one constructor to begin with. However, if several constructors are available, at least one must be annotated to teach the container which one to use.

public class MovieRecommender {

    private final CustomerPreferenceDao customerPreferenceDao;

    // @Autowired
    public MovieRecommender(CustomerPreferenceDao customerPreferenceDao) {
        this.customerPreferenceDao = customerPreferenceDao;
    }

}

 

posted @ 2019-03-30 17:36  beidoufeng  阅读(124)  评论(0编辑  收藏  举报