Ch05 ConfigureProperties

8/13/2021 JavaSpring

可以读取properties文件中的配置并进行绑定,prefix中不能有大写字母!!!

image-20230425175548244

image-20230425175555320

测试:

image-20230425175606575

如果在使用第三方类的配置绑定功能,类中没有@Component,那么可以用以下方式:

image-20230425175617416

开启配置绑定功能,并把People注册到容器中

image-20230425175629735

出现如下错误:

image-20230425175640017

在pom.xml中增加如下依赖

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
1
2
3
4
5
Last Updated: 11/19/2024, 1:54:38 PM