Create a file per application named like the application war file and have the file sitting in the Tomcat 7 conf/Catalina/localhost/ directory.
Each file can then contain some environment variables specific to the application.
For example, the two applications project1.war and project2.war deployed in the webapps directory.
In the file conf/Catalina/localhost/project1.xml
<Context path="" docBase="project1">
<Environment name="product" value="one" type="java.lang.String" override="false" />
</Context>
conf/Catalina/localhost/project2.xml
<Context path="" docBase="project1">
<Environment name="product" value="two" type="java.lang.String" override="false" />
</Context>
Also I didn't experience the double deployment.
My development server host is:
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true" deployOnStartup="true">
And my production server host is:
<Host name="www.learnintouch.com" appBase="webapps" unpackWARs="true" autoDeploy="true" deployOnStartup="true">
To retrieve the value of the variable, I use the Spring condition context:
public class ProductProjectCondition implements Condition {
@Override
public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
return context.getEnvironment().getProperty("product") == null || context.getEnvironment().getProperty("product").equals("project");
}
}
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Conditional(ProductProjectCondition.class)
public @interface ProductProject {
}
It is then possible to use the @ProductProject annotation.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…