1 回答

TA貢獻1906條經驗 獲得超10個贊
1) 當兩個 Spring-Boot 應用程序在同一個 tomcat 上運行時,您通常會遇到數據源的實例化可能會失敗的問題,因為已經存在同名的實例。這是您在問題中描述的例外。
這可以通過為每個 Spring-Boot 應用程序添加一個唯一的名稱來解決,例如在
application.yml
spring:
application:
name: application-name-1
jmx:
default-domain: application-name-1
2)為每個Spring-Boot應用程序提供外部配置可以通過tomcat上下文配置為每個應用程序單獨完成。假設所有應用程序都部署為.wareg app1.war,app2.war我們需要為兩個應用程序配置上下文,如下所示:
創建以下文件(如果丟失,則創建目錄)
tomcat-base-dir
/conf
/catalina
/localhost #must be the same as specified in the Host tag in the server.xml
app1.xml #must have the same name as the .war application file
app2.xml
內容為app1.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- docBase must contain be the name of the application to be configured -->
<Context docBase="app1.war">
<Parameter name="spring.config.location" value="${catalina.base}/conf/app1.yml" />
</Context>
這將配置應用程序app1.war以使用該文件app1.yml進行配置。對 app2 執行相同的操作。實際的配置文件app1.yml可以位于值中指定的任何路徑。
添加回答
舉報