依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId></dependency>
yml配置
student:red: com.ma.config.MinIOConfigProperties
spring.factories
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\com.heima.file.service.impl.MinIOFileStorageService,\.....,\....
config
@Data
@Configuration
@ConfigurationProperties(prefix = "student") // 文件上传 配置前缀file.oss
public class MinIOConfigProperties implements Serializable {private String red;
}
Test测试类 | ServiceImpl业务逻辑层
@EnableConfigurationProperties(MinIOConfigProperties.class)
@Import(MinIOConfigProperties.class)
这个两个注解都可以完成注入Bean的操作
@SpringBootTest
//@EnableConfigurationProperties(MinIOConfigProperties.class)
@Import(MinIOConfigProperties.class)
class SpringBootTest01ApplicationTests {@Autowiredprivate MinIOConfigProperties minIOConfigProperties;@Testvoid contextLoads() {// 获取accessKey值String accessKey = minIOConfigProperties.getRed();System.out.println(accessKey);}
}