每日笔记---使用@ConfigurationProperties读取yml配置
参考地址 https://www.cnblogs.com/mycs-home/p/8352140.html
1.添加pom依赖
1
2
3
4
5
|
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>
true
</optional>
</dependency>
|
2.application.yml文件中添加需要配置的属性,注意缩进
1
2
3
4
5
|
Myyml:
username: cs
password:
123456
url: jdbc:mysql:
//localhost:3306/test
driver: com.mysql.jdbc.Driver
|
3.新建一个类,@Component注解表明是组件,可被自动发现,@ConfigurationProperties注解之前是location属性表明配置文件位