在 Spring-MVC 中部署多个环境
目前,所有 Web 应用程序都使用单独的配置文件进行部署:
<!-- <import bean.... production/> -->
<import bean... development/>
这有缺点,即使您只需要换出一个配置文件,我相信每个人都熟悉这一点(想知道不通过 XML 搜索而刚刚部署的内容就是其中之一)
我想将日志添加到我的应用程序中,基本上是“在生产模式下运行”,并描述已部署的服务以及它们工作的模式。
RUNNING IN PRODUCTION MODE
Client Service - Production
Messaging Service - Local
等等...
在 Spring 中使用传统部署(将服务器上的战争)?人们还做哪些其他事情来管理部署和软件配置?
如果没有,您还可以通过哪些其他方式实现类似的目标?
Currently all web apps are deployed using seperate config files:
<!-- <import bean.... production/> -->
<import bean... development/>
This has disadvantages, even if you only need to swap out one config file, that I'm sure everyone is familiar with (wondering what just deployed without searching through XML is one of them)
I want to add Logging to my application that basically says 'RUNNING IN PRODUCTION MODE', with a description of the services deployed and what mode they are working in.
RUNNING IN PRODUCTION MODE
Client Service - Production
Messaging Service - Local
and so on...
Is this possible in Spring using a conventional deployment (putting a war on a server)? What other things do people do to manage deployments and software configurations?
If not, what other ways could you achieve something similar?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的。您可以使用
PropertyPlaceholderConfigurer
动态添加属性,并在每个环境中拥有不同的属性文件。例如:这个是从类路径加载的,它可能适合您,也可能不适合您,具体取决于您启动应用程序的方式。因此,您可以在其中设置如下属性:
然后,您可以选择几个选项来了解如何将其发送到网页。也许最简单的方法是使用拦截器添加请求属性并从 Spring 配置注入
$(environment.message}
的值。无论如何,希望这能为您指明正确的方向。
Yes it is. You use a
PropertyPlaceholderConfigurer
to dynamically add properties and have a different properties file in each environment. For example:This one is loaded from the classpath, which might work for you or might not depending on how you start your application. So you can properties in it like:
You then have a few options on how to get this to a Web page. Probably the simplest is to use an interceptor to add a request attribute and inject the value of
$(environment.message}
from Spring config.Anyway, hope that points you in the right direction.
使用 Spring 3.1 中添加的配置文件功能也可以实现这一点。请参阅此处。
This is also possible using the profiles feature added in Spring 3.1. See here.