开发者

Deploying Multiple Environments in Spring-MVC

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 
开发者_如何学CClient 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?


Yes it is. You use a PropertyPlaceholderConfigurer to dynamically add properties and have a different properties file in each environment. For example:

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

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:

environment.message=DEVELOPMENT ENVIRONMENT

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.


This is also possible using the profiles feature added in Spring 3.1. See here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜