浅谈SpringBoot自动装配( 二 )

简单来说就是,举个例子,当HSQLDB存在于应用的Classpath中时,开发人员不需要手动配置数据库连接的Beans,而是由SpringBoot自动装配一个内存型的数据库Beans,开发人员可以直接使用。

官方文档介绍的激活自动装配的方法:

You need to opt-in to auto-configuration by adding the @EnableAutoConfiguration or @SpringBootApplication annotations to one of your @Configuration classes.

文档中提到激活自动化装配的注解@EnableAutoConfiguration和@SpringBootApplication,将两者选其一标注在@Configuration类上即可实现自动装配。

实现自动装配

org.springframework.boot

spring-boot-starter-web

@SpringBootApplication

public class AutoConfigurationBootStrap {

public static void main(String[] args) {

推荐阅读