1

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?

4

2 回答 2

2

是的。您可以使用 aPropertyPlaceholderConfigurer动态添加属性并在每个环境中拥有不同的属性文件。例如:

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
  <property name="location" value="classpath:environment.properties"/>
</bean>

这个是从类路径加载的,它可能对您有用,也可能不取决于您启动应用程序的方式。因此,您可以在其中使用以下属性:

environment.message=DEVELOPMENT ENVIRONMENT

然后,您有一些关于如何将其发送到网页的选项。可能最简单的方法是使用拦截器添加请求属性并$(environment.message}从 Spring 配置中注入 的值。

无论如何,希望这能为您指明正确的方向。

于 2010-04-25T14:49:22.367 回答
1

这也可以使用Spring 3.1 中添加的配置文件功能。这里

于 2012-03-04T00:39:12.507 回答