Spring Boot JAR
先用 jar tf 看目录结构:
jar tf xxx.jar | head
如果能看到 BOOT-INF/classes/,就是 Spring Boot 可执行 JAR;应用类和资源在 BOOT-INF/classes/,依赖在 BOOT-INF/lib/:
jar tf xxx.jar | rg '^BOOT-INF/(classes|lib)/' | head
内置配置文件:
jar tf xxx.jar \
| rg '^BOOT-INF/classes/application[^/]*\.(properties|ya?ml)$'
读取配置:
unzip -p xxx.jar BOOT-INF/classes/application.yml
如果配置不在 JAR 里,再看进程参数里的 --spring.config.location、--spring.config.additional-location 和 -Dspring.config.location:
ps -eo pid,args | rg '[j]ava'
外置 Tomcat
定位 org.apache.catalina.startup.Bootstrap 进程:
ps -eo pid,args | rg '[o]rg.apache.catalina.startup.Bootstrap'
当时进程里的关键参数是这些,实际路径已替换:
java \
-Djava.util.logging.config.file=<tomcat-dir>/conf/logging.properties \
-classpath <tomcat-dir>/bin/bootstrap.jar:<tomcat-dir>/bin/tomcat-juli.jar \
-Dcatalina.base=<tomcat-dir> \
-Dcatalina.home=<tomcat-dir> \
-Djava.io.tmpdir=<tomcat-dir>/temp \
org.apache.catalina.startup.Bootstrap start
catalina.base 和 catalina.home 都指向同一个目录,所以配置就在这个目录的 conf/ 下:
<tomcat-dir>/conf/
<tomcat-dir>/logs/
<tomcat-dir>/webapps/
<tomcat-dir>/temp/
多实例部署时 catalina.base 和 catalina.home 也可能不同,定位配置时以 catalina.base 为准。
参考
Spring Boot Externalized Configuration
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。