What is the difference between Spring Boot's auto-configuration and auto-wiring?
Is it that, autowiring is injection of a Bean into another class, and auto-configuration is the term used for complete auto-wired application?
If you don’t want to use @SpringBootApplication, the @EnableAutoConfiguration and @ComponentScan annotations that it imports defines that behaviour so you can also use that instead.
@SpringBootApplication actually defines @EnableAutoConfiguration and @ComponentScan
Spring Boot auto-configuration attempts to automatically configure your Spring application based on the jar dependencies that you have added
All of your application components (@Component, @Service, @Repository, @Controller etc.) are automatically registered as Spring Beans.
● @Autowired is used for dependency injection
Auto-configuration in Spring refers to what Spring does for you to configure your application based on the dependencies that you have added. Instead of having bean definitions and having to configure your own stuff in Spring MVC (Do you remember the amount of xml configs you had to do?), Spring Boot essentially "listens" for things on your class path, and if it's something that it's able to auto-configure for you, it'll do so.
The @SpringBootApplication
annotation automatically opts you into having Spring automatically configure various beans for you.
You are correct in the sense that auto-wiring relates to Dependency Injection. Having the annotation @Autowired
inside one of your classes, means that you bring an instance of the class that's being annotated, into the class that the annotation exists in.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.