META-INF的spring.factories文件配置自动注入配置类
#-------starter自动装配---------
org.springframework.boot.autoconfigure.EnableAutoConfiguration =\
com.mao.springboot.my.springboot.starter.config.MyConfig
读取yml文件my.前缀的配置数据,注入到MyProperties对象,交spring管理 ```java @Data @ConfigurationProperties(prefix = “my”) @PropertySource(“classpath:my-property.yml”) public class MyProperties {
private String sayWhat;
private String toWho;
}
�// 根据配置文件读取到的MyProperties对象的配置信息,进行自动装配MyConfig对象
```java
@Configuration
@EnableConfigurationProperties(MyProperties.class)
@ConditionalOnProperty(
prefix = "my",
name = "isopen",
havingValue = "true"
)
public class MyConfig {
@Autowired
private MyProperties myProperties;
@Bean(name = "my")
@ConditionalOnMissingBean()
public MyService myService() {
return new MyService(myProperties.getSayWhat(), myProperties.getToWho());
}
}