我正在查看工作区中的一些旧示例。我看不出怎么样 由于没有 @Autowired, Autowiring 完成。 Spring boot + facebook 默认配置。
@Controller
@RequestMapping("/")
public class HelloController {
private Facebook facebook;
private ConnectionRepository connectionRepository;
public HelloController(Facebook facebook, ConnectionRepository connectionRepository) {
this.facebook = facebook;
this.connectionRepository = connectionRepository;
}
@GetMapping
public String helloFacebook(Model model) {
System.out.println("we are here!!!");
if (connectionRepository.findPrimaryConnection(Facebook.class) == null) {
return "redirect:/connect/facebook";
}
PagedList<Post> feed = facebook.feedOperations().getFeed();
model.addAttribute("feed", feed);
return "hello";
}
}
它工作得很好,但是这些 beans 如何在没有 @Autowired 的情况下 Autowiring 自己? 它们是作为字段还是在构造函数中 Autowiring 的?
最佳答案
使用 spring boot 1.4+ 构造函数会自动 Autowiring
关于java - 不带注解的 Autowiring @Autowired,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43363122/