没有注释的自动装配@Autowired [英] Autowire without annotation @Autowired

查看:106
本文介绍了没有注释的自动装配@Autowired的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看工作区中的一些旧示例.我看不出来 自动布线完成,因为没有 @Autowired . Spring Boot + Facebook默认配置.

I am looking at some old example I have in the workspace. I can't see how is the autowiring done as there is no @Autowired. Spring boot + facebook default configurations.

@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";
    }
}

它的工作原理很完美,但是这些bean如何在没有@Autowired的情况下自动进行自动连线? 它们是作为字段或在构造函数中自动布线的吗?

It works perfect but how these beans autowire themselves without the @Autowired? Are they autowired as a field or in the constructor?

推荐答案

借助Spring Boot 1.4+,构造函数会自动进行自动接线

With spring boot 1.4+ constructors are automatically autowired

查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆