版本:springboot-verison 3.1.2 如图所示,application.yaml Spring application.yaml的字段取值不正确 图上为的access-key为minioAdmin;access-secret为minioAdmin123456 写了MinioProperies,自动生成的get set 方法,没有用lombok 代码如下

@Component
@ConfigurationProperties(prefix = "minio",ignoreInvalidFields=true)
public class MinioProperties {

    private String endpoint;
    private String accessKey;
    private String accessSecret;
    private String bucketName;

    public String getEndpoint() {
        return endpoint;
    }

    public void setEndpoint(String endpoint) {
        this.endpoint = endpoint;
    }

    public String getAccessKey() {
        return accessKey;
    }

    public void setAccessKey(String accessKey) {
        this.accessKey = accessKey;
    }

    public String getAccessSecret() {
        return accessSecret;
    }

    public void setAccessSecret(String accessSecret) {
        this.accessSecret = accessSecret;
    }

    public String getBucketName() {
        return bucketName;
    }

    public void setBucketName(String bucketName) {
        this.bucketName = bucketName;
    }
}

so 在MinioConfig中去取值MinioProperties的值,代码如下:

@Configuration
@Slf4j
public class MinioConfig {

    @Resource
    private MinioProperties minioProperties;

    @Value("${minio.access-key}")
    private String accessKey;


    @Bean
    public MinioClient minioClient() throws ServerException, InsufficientDataException, ErrorResponseException, IOException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        MinioClient minioClient = MinioClient.builder()
                .endpoint(minioProperties.getEndpoint())
                .credentials(minioProperties.getAccessSecret(), minioProperties.getAccessSecret())
                .build();
        if(!minioClient.bucketExists(BucketExistsArgs.builder().bucket(minioProperties.getBucketName()).build())){
            minioClient.makeBucket(MakeBucketArgs.builder().bucket(minioProperties.getBucketName()).build());
        }
        return minioClient;
    }
}

看代码感觉没什么问题,但是差异的(amazing)事情发生了,如图所示 Spring application.yaml的字段取值不正确

why the accessKey is minio,not minioadmin,I do not known what happen; I think this is a issue;so i want to tick this question; I want to konw why;thanks very much to tell this answer;

Comment From: liutinggang

同时我还去验证了以前用springboot2.0写的,没有出现过这种情况

Comment From: sbrannen

Thanks for getting in touch, but it feels like this is a question that would be better suited to Stack Overflow. As mentioned in the guidelines for contributing, we prefer to use the issue tracker only for bugs and enhancements. Feel free to update this issue with a link to the re-posted question (so that other people can find it) or add some more details if you feel this is a genuine bug.

Furthermore, if you encounter issues specific to Spring Boot, please use the Spring Boot issue tracker.

Comment From: liutinggang

非常感谢,我忘记了这里是spring-framework的问题答疑区,应该去springboot的地方,十分抱歉。我个人认为应该是springboot自动注入可能对某些字段或者驼峰命名法或者对admin有点特殊的处理。我想去看看源码。然后再来和您讨论一下。

Thank you very much. I forgot that this is the question and answer area of spring-framework. I should go to springboot. My personal opinion is that springboot auto injection may have some special treatment for some fields or hump nomenclature or admin. I want to see the source code. Then I'll come back and discuss it with you.