Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

384
Views
Autowire without annotation @Autowired

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?

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

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

about 4 years ago · Santiago Trujillo Report

0

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.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!