升到 Spring Boot 4.2.0-RC1 时,配置里还留着 logging.path、spring.application.index 这类旧键。想让 migrator 更严一点,把 spring.properties.migrator.fail 收到 on-error 或 on-warning,进程会直接挂:日志先打出旧键报告,再来 Application run failed 和 IllegalStateException: Found configuration keys that need to be migrated,退出码 1。默认 never 只警告,应用还能起来。

环境是 JDK 21.0.12.1、Boot 4.2.0-RC1。runtime 挂上 migrator:

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-properties-migrator</artifactId>
  <scope>runtime</scope>
</dependency>

RC1 发行说明「Properties Migrator Fail Support」给 migrator 加了失败开关;附录键名是 spring.properties.migrator.fail,取值 never(默认)、on-error、on-warning。migrator 模块本身很早就有,这次新的是能把报告升级成启动失败。升级窗口里可以先用它扫出还在用的旧键;CI 里再决定要不要长期开着。

先不碰 fail,只带着改名键启动:

java -jar app.jar --logging.path=logs-demo
2026-10-27T08:12:48.179+08:00  INFO 506771 --- [           main] c.e.m.MigratorFailApplication            : Started MigratorFailApplication in 0.581 seconds (process running for 0.829)
2026-10-27T08:12:48.181+08:00  WARN 506771 --- [           main] o.s.b.c.p.m.PropertiesMigrationListener  : 
The use of configuration keys that have been renamed was found in the environment:

Property source 'commandLineArgs':
	Key: logging.path
		Replacement: logging.file.path


Each configuration key has been temporarily mapped to its replacement for your convenience. To silence this warning, please update your configuration to use the new keys.

exit=0

进程起来了。WARN 写明 logging.path 已改名,替代键是 logging.file.path,当前只是临时映射。换成已删除的 spring.application.index,级别变成 ERROR,照样 exit=0:

java -jar app.jar --spring.application.index=1
2026-10-27T08:12:49.009+08:00  INFO 506821 --- [           main] c.e.m.MigratorFailApplication            : Started MigratorFailApplication in 0.538 seconds (process running for 0.792)
2026-10-27T08:12:49.012+08:00 ERROR 506821 --- [           main] o.s.b.c.p.m.PropertiesMigrationListener  : 
The use of configuration keys that are no longer supported was found in the environment:

Property source 'commandLineArgs':
	Key: spring.application.index
		Reason: Application context ids are now unique by default.


Please refer to the release notes or reference guide for potential alternatives.

exit=0

Reason 写得很直:Application context ids are now unique by default。日志里「renamed」和「no longer supported」是两类问题;默认 fail 都只报、不拦。

升级时若先只想挡住已删除键,打开 on-error,再带上 spring.application.index:

java -jar app.jar --spring.application.index=1 --spring.properties.migrator.fail=on-error
The use of configuration keys that are no longer supported was found in the environment:

Property source 'commandLineArgs':
	Key: spring.application.index
		Reason: Application context ids are now unique by default.

2026-10-27T08:12:49.598+08:00 ERROR 506855 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Found configuration keys that need to be migrated
exit=1

同一条 unsupported 报告之后,Spring Boot 打出 Application run failed,异常文案是 Found configuration keys that need to be migrated,进程退出 1。只带着改名键 logging.path、同样开 on-error,则仍能启动:

2026-10-27T08:12:50.428+08:00  INFO 506923 --- [           main] c.e.m.MigratorFailApplication            : Started MigratorFailApplication in 0.547 seconds (process running for 0.791)
2026-10-27T08:12:50.431+08:00  WARN 506923 --- [           main] o.s.b.c.p.m.PropertiesMigrationListener  : 
The use of configuration keys that have been renamed was found in the environment:

Property source 'commandLineArgs':
	Key: logging.path
		Replacement: logging.file.path

exit=0

on-error 只认 unsupported 那一类。改名键还在用时,进程不会因为这一档停住。

若升级验收要求改名键也不能过,收到 on-warning:

java -jar app.jar --logging.path=logs-demo --spring.properties.migrator.fail=on-warning
2026-10-27T08:12:51.037+08:00  WARN 507011 --- [           main] o.s.b.c.p.m.PropertiesMigrationListener  : 
The use of configuration keys that have been renamed was found in the environment:

Property source 'commandLineArgs':
	Key: logging.path
		Replacement: logging.file.path


Each configuration key has been temporarily mapped to its replacement for your convenience. To silence this warning, please update your configuration to use the new keys.

2026-10-27T08:12:51.045+08:00 ERROR 507011 --- [           main] o.s.boot.SpringApplication               : Application run failed

java.lang.IllegalStateException: Found configuration keys that need to be migrated
exit=1

还是那条 renamed WARN,紧接着同样的 IllegalStateException 和退出码 1。读日志时先看 migrator 报的是 renamed 还是 no longer supported,再看后面有没有 Application run failed;有失败栈就说明当前 fail 档位已经把报告抬成了启动错误。

要解卡:把 logging.path 改成 logging.file.path;删掉或换掉 spring.application.index(metadata 给出的原因就是 Application context ids are now unique by default.)。旧键清干净后,再决定 CI 里是否继续留着 on-warning,避免以后又混进过期键。同一次 RC1 里默认 Ubuntu 26.04 builder 和 bindings 的启动问题,见 Spring Boot 4.2.0-RC1 默认 Ubuntu 26.04,bindings 会启动失败,那篇用的是另一组旧键。

依据:Spring Boot 4.2.0-RC1 Release Notes、附录 Application Properties、Upgrading Spring Boot。

— 感谢阅读 —
广告

一起交流

分享你的思考,让讨论更进一步。