application.properties无法修改成yml
时间: 2025-03-06 15:24:06 浏览: 52
### 将 `application.properties` 转换为 `application.yml`
为了将 Spring Boot 项目的 `application.properties` 文件转换为 `application.yml` 格式,可以遵循以下方法:
#### 方法一:手动转换
假设当前的 `application.properties` 文件如下所示[^3]:
```properties
server.port=8089
spring.datasource.url=jdbc:mysql://localhost:3306/testdb?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=password
```
将其转换为 `application.yml` 的格式应为:
```yaml
server:
port: 8089
spring:
datasource:
url: jdbc:mysql://localhost:3306/testdb?useSSL=false&serverTimezone=UTC
username: root
password: password
```
#### 方法二:使用工具辅助转换
一些 IDE 和在线工具可以帮助完成此过程。例如,在 IntelliJ IDEA 中右键点击 `.properties` 文件并选择 "Convert to YAML" 可以快速实现转换。
#### 修改项目读取配置文件的方式
如果希望应用程序优先读取特定命名的 YML 文件(如 `application_custom.yml`),可以在启动类中指定配置文件位置[^2]:
```java
@SpringBootApplication
public class HelloworldApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(HelloworldApplication.class)
.properties("spring.config.name=application_custom")
.run(args);
}
}
```
需要注意的是,默认情况下 Spring Boot 支持同时存在 `.properties` 和 `.yml` 文件,并按照一定顺序加载这些配置文件[^1]。因此当两者共存时,某些配置可能会被覆盖或忽略。
阅读全文
相关推荐


















