I'm experimenting with examples from this official Spring tutorials and there is a dependency on this code:
https://github.com/spring-guides/gs-async-method/tree/master/complete
If you look at the code on AppRunner.java
class, I have 2 questions:
- When server is starting, if I put a breakpoint in this class's constructor, seems like in the constructor, the
GitHubLookupService
is provided by spring, using the@Service
bean that was configured. BUT, there was no@Autowired
annotation on the constructor, so how in the world this constructor get called with the right dependency? It was supposed to benull
.
Is it an automatic assumption of Spring Boot?
Does Spring see "private field + constructor argument, and it assumes it should look for an appropriate bean?
Is it Spring Framework or Spring boot?
Am I missing something?
- As I remember, it was mendatory to provide default constructor to beans / service etc. How come this class (
AppRunner
) doesn't have a default constructor? How does Spring knows that it should run the constructor with the argument? Is it because it is the only constructor?