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可以位于值中指定的任何路径。
添加回答
举报