8

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

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

strash
  • 1,291
  • 2
  • 15
  • 29
  • 1
    Have you subscribed all the users to an Amazon SNS topic, or do you send messages to individual users (without using a Topic)? – John Rotenstein Apr 12 '17 at 11:40
  • individual users – strash Apr 12 '17 at 18:12
  • What do you mean by "amazon continues to send notifications"? Are they notifications from your application? How were they sent to SNS? Or are you talking about retries? Please Edit your question to provide additional information so that we can assist you. – John Rotenstein Apr 12 '17 at 22:49
  • Put a "final" to your members, then IntelliJ will give you nice feedback if entities are used or not, making it easy to kick out unused beans. – kaiser Aug 23 '23 at 06:28

2 Answers2

15

With spring boot 1.4+ constructors are automatically autowired

https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-spring-beans-and-dependency-injection.html

Darren Forsythe
  • 10,712
  • 4
  • 43
  • 54
-1

In this controller you have not given any annotation @Autowired and may be you have the interface in the controller so you dont need to give the annotation and further also check in the service layer @Service annotation is there or not if you have not given @Service you are not able to use @Autowired also.