SpringBoot自动配置注入Bean工具autoconfigure

依赖

      
            org.springframework.boot
            spring-boot-autoconfigure
        

SpringBoot自动配置注入Bean工具autoconfigure_第1张图片

yml配置

student:
  red: com.ma.config.MinIOConfigProperties

SpringBoot自动配置注入Bean工具autoconfigure_第2张图片

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 {
    
    @Autowired
    private MinIOConfigProperties minIOConfigProperties;

    @Test
    void contextLoads() {
        // 获取accessKey值
        String accessKey = minIOConfigProperties.getRed();
        System.out.println(accessKey);
    }
}

你可能感兴趣的:(SpringBoot,spring,boot,java,spring)