我有一个 Spring Boot 应用程序,它为 tomcat 使用自定义 context.xml。 context.xml 包含属性,定义 spring Activity 配置文件
<Context>
<Environment name="spring.profiles.active" value="profileName" type="java.lang.String" override="false" />
</Context>
文件位置是/src/main/webapps/META-INF 我期望在文件部署到 tomcat 后,tomcat 会自动选择上下文 xml 并将其扔到 conf/catalina/localhost/
事实证明, war 已经部署,但是 conf/catalina/localhost 仍然是空的。
阅读文档后,我发现必须使用 copyXML 参数更新 server.xml 作为主机容器。 文档说:
copyXML Set to true if you want a context XML descriptor embedded inside the application (located at /META-INF/context.xml) to be copied to xmlBase when the application is deployed. On subsequent starts, the copied context XML descriptor will be used in preference to any context XML descriptor embedded inside the application even if the descriptor embedded inside the application is more recent. The flag's value defaults to false. Note if deployXML is false, this attribute will have no effect.
我的主机看起来像
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true" copyXML="true">
</Host>
重启服务器并重新部署应用后,/conf/Catalina/localhost 仍然是空的。
您有什么建议,必须采取什么行动才能使用自定义 context.xml?
最佳答案
我想通了。 我的构建脚本没有正确复制文件,文件名不是“context.xml”而是“appName.xml”,而 tomcat 没有拾取它。
关于java - 部署 war 。 Tomcat 没有考虑 META-INF 中的 context.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58389644/