Spring Boot升级后Tomcat抛出MalformedURLException:未知协议classpath
解决Spring Boot 2.0.1升级后SSL配置失效的问题
我之前升级Spring Boot版本时也踩过这个坑!问题出在Spring Boot 2.0正式版发布后,SSL配置的属性结构和命名都做了调整,你用的spring.ssl.*系列属性在2.0.1版本里已经被废弃,并且不再支持classpath:前缀的解析,这才导致了java.net.MalformedURLException: unknown protocol: classpath异常。
具体解决方案:
迁移配置到正确的属性节点
把原来spring.ssl下的配置全部移到server.ssl节点下,同时注意属性名的标准化(Spring Boot 2.0+更推荐短横线分隔的命名风格):keystoreFile→key-storekeystorePass→key-store-passwordtruststoreFile→trust-storetruststorePass→trust-store-password
修正后的application.yml示例
server: schema: "https" address: "localhost" port: 8080 sslPort: 8443 servlet: session: timeout: 900 ssl: enabled: true # 务必加上这个,启用SSL功能 key-store: classpath:.keystore key-store-password: **** trust-store: classpath:.truststore trust-store-password: **** spring: profiles: active: dev
额外说明:
- 确保你的
.keystore和.truststore文件确实放在src/main/resources目录下,这样打包后会被正确加入classpath; - 旧版本2.0.0.M7作为里程碑版本,当时的SSL配置还在迭代中,
spring.ssl是临时配置节点,正式版发布后统一整合到了server.ssl下,同时优化了资源路径的解析逻辑,现在classpath:前缀可以被正确识别。
内容的提问来源于stack exchange,提问作者Maksym Mazur
相关产品推荐
相关产品推荐

