1 带@Configuration注解的类,该类本身首先会被SpringBoot注入到IOC容器中;
2 SpringBoot同时会扫描该类中带@Bean注解的方法,调用该方法来创建Bean,并且将该Bean注入到IOC容器中
示例如下:
@Configuration
@EnableConfigurationProperties(PhoneProperties.class)
public class DemoConfig {
@Autowired
private PhoneProperties phoneProperties;
@Bean
public Phone phone() {
return new Phone(phoneProperties.getType(), phoneProperties.getPrice());
}
}
关于@EnableConfigurationProperties,PhoneProperties,Phone的更多详情,可以参看@ConfigurationProperties