如何在tomcat服务器上运行具有不同弹簧配置文件的两个WAR文件? [英] How to run two WAR files with different spring profiles on a tomcat server?

查看:137
本文介绍了如何在tomcat服务器上运行具有不同弹簧配置文件的两个WAR文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一个tomcat服务器上并行运行我的spring应用程序两次。一次使用生产个人资料,一次使用 dev 个人资料。

I would like to run my spring application two times, in parallel, on the same tomcat server. One time with a production profile and one time with a dev profile.

我还想为两个配置文件构建一个单独的WAR。

I also would like to build one single WAR for the two profiles.

我已经成功地在我的应用程序中集成了配置文件 @Profile 注释。我已经在我的tomcat服务器上成功部署了两个WAR文件。

I've successfully integrated profiles in my application with @Profile annotations. I've successfully deployed the two WAR files on my tomcat server.

我需要的是在这两个应用程序中激活不同配置文件的意思,具有约束这两个应用程序使用相同WAR文件的副本,并且两个应用程序应并行运行。

What I need is a mean to activate a different profile on each of theses two applications, with the constraint that these two applications use a copy of the same WAR file and that the two applications should run in parallel.

所以 WebApplicationInitializer web.xml 似乎不是选项。

推荐答案

记录:

激活 dev 应用程序中的弹出配置文件 application-dev.war

To activate the dev spring profile on the application in application-dev.war

创建文件< CATALINA_BASE> /conf/Catalina/localhost/application-dev.xml

With以下内容:

<Context>
  <Environment name="spring.profiles.active" value="dev,server" type="java.lang.String" override="false" />
</Context>

这设置 spring.profiles.active application-dev.war 运行的应用程序的 dev,server 的属性。

This set the spring.profiles.active property to dev,server for the application run by application-dev.war.

感谢您的回答: https://stackoverflow.com/a/26653238/1807667

PS: server.xml中使用 autoDeploy = true 配置文件消失 on tomcat restart。

P.S.: With autoDeploy=true in server.xml, the configuration files disappear on tomcat restart.

解决方案是添加< Context reloadable =true> in < CATALINA_BASE> /conf/context.xml 但要注意根据文档

Solution is to add <Context reloadable="true"> in <CATALINA_BASE>/conf/context.xml but beware that according to documentation :


此功能在应用程序开发期间非常有用,但它
需要signifi运行时开销不大,建议不要在已部署的生产应用程序上使用

This feature is very useful during application development, but it requires significant runtime overhead and is not recommended for use on deployed production applications.

此外还使用 < Context reloadable =true> 并未完全解决配置文件在某些​​重新启动时仍然消失的问题。

and moreover using <Context reloadable="true"> does not solve fully the issue the configuration files still disappear for some restart.

PS2: docBase 属性>上下文元素,请参阅此问题

这篇关于如何在tomcat服务器上运行具有不同弹簧配置文件的两个WAR文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆