문제

As being develop a big project using Spring and maven. However there will be different environments to be deployed such as dev, test, staging and production.

The project is having a lot of different properties for different environments.

Are there any elegant way to solve this kind of thing, so I can use this as a template and reuse in other projects.

I guess spring features such as profile, placeholders and etc will be used.

Are there any good tutorial or some blog for me to get a better solution for that?

도움이 되었습니까?

해결책

The Maven concept profile can be your friend :

    <profile>
        <id>DEV</id>
        <build>
            <resources>
                <resource>
                    <directory>src/test/dev-resources</directory>
                </resource>
                <resource>
                    <directory>src/main/dev-resources</directory>
                </resource>
            </resources>
         </build>
   </profile>
   <profile>
            <id>STAGING</id>
            <build>
              <resources>
                <resource>
                    <directory>src/test/staging-resources</directory>
                </resource>
                <resource>
                    <directory>src/main/staging-resources</directory>
                </resource>
              </resources>
            </build>
    </profile>

and run all your Maven build with "-P DEV" for dev propose and "-P STAGING" for staging propose for example .

다른 팁

You can use property configurer. Something like this:

<bean id="propertyConfigurer"
      class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="ignoreResourceNotFound" value="true"/>
    <property name="locations">
        <list>
            <value>file:${catalina.home}/conf/your_props.properties</value>
        </list>
    </property>
</bean>

And you can put your properties (in this case Tomcat servlet container is used) under some config directory in each different environment.

In this case properties are stored under ${catalina.home}/conf where catalina.home refers to Tomcat's installation directory.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top