Configuration Management
Relevant source files
The following files were used as context for generating this wiki page:
Configuration management in the zheng project is handled at build-time using Apache Maven. This strategy leverages Maven profiles to manage distinct configurations for different environments, such as development, testing, and production. By defining environment-specific properties and filtering resources during the build process, the system ensures that each packaged application artifact contains the correct settings for its target environment.
This approach centralizes configuration concerns within the build system, allowing for a clean separation between code and configuration. It is a consistent pattern applied across all modules in the project.
Maven-based Configuration
The core of configuration management is implemented in the pom.xml file of each module. It relies on two key Maven features: Profiles and Resource Filtering.
Environment Profiles
Most modules define three standard Maven profiles: dev, test, and prod. Each profile is responsible for setting an env property that corresponds to the target environment.
The dev profile is enabled by default, making it the standard for local development builds unless another profile is explicitly activated.
<!-- zheng-cms/zheng-cms-admin/pom.xml -->
<profiles>
<profile>
<id>dev</id>
<properties>
<env>dev</env>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<env>test</env>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<env>prod</env>
</properties>
</profile>
</profiles>
Sources: zheng-cms/zheng-cms-admin/pom.xml:41-64, zheng-cms/zheng-cms-web/pom.xml:52-75, zheng-oss/zheng-oss-admin/pom.xml:51-74
The following table summarizes the standard profiles:
| Profile ID | env Property Value | Default | Purpose |
|---|---|---|---|
dev | dev | Yes | For local development environments. |
test | test | No | For dedicated testing environments. |
prod | prod | No | For production deployment. |
| Sources: zheng-cms/zheng-cms-admin/pom.xml:41-64 |
Resource Filtering
The env property set by the active profile is used to select a corresponding properties file. The Maven build is configured to filter files in the src/main/resources directory, replacing placeholders with values from the selected properties file.
This is configured in the <build> section of the pom.xml:
<!-- zheng-cms/zheng-cms-admin/pom.xml -->
<build>
<finalName>zheng-cms-admin</finalName>
<filters>
<filter>src/main/resources/profiles/${env}.properties</filter>
</filters>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
Sources: zheng-cms/zheng-cms-admin/pom.xml:67-77, zheng-cms/zheng-cms-rpc-service/pom.xml:52-62
The diagram below illustrates the build process flow.
This diagram shows how activating a Maven profile determines which .properties file is used to filter application resources.
Sources: zheng-cms/zheng-cms-admin/pom.xml:41-77, zheng-cms/zheng-cms-web/pom.xml:52-87
Module-Specific Configurations
While the profile and filtering mechanism is standard, specific configurations, such as the embedded Jetty server port, are defined on a per-module basis within their pom.xml files. This allows multiple services to run concurrently on a development machine without port conflicts.
The following table lists the default Jetty ports for various web-facing modules:
| Module | pom.xml File | Jetty Port |
|---|---|---|
zheng-upms-server | zheng-upms/zheng-upms-server/pom.xml | 1111 |
zheng-cms-admin | zheng-cms/zheng-cms-admin/pom.xml | 2222 |
zheng-cms-job | zheng-cms/zheng-cms-job/pom.xml | 2223 |
zheng-cms-web | zheng-cms/zheng-cms-web/pom.xml | 2224 |
zheng-api-server | zheng-api/zheng-api-server/pom.xml | 6666 |
zheng-oss-admin | zheng-oss/zheng-oss-admin/pom.xml | 7772 |
| Sources: zheng-upms/zheng-upms-server/pom.xml:100, zheng-cms/zheng-cms-admin/pom.xml:90, zheng-cms/zheng-cms-job/pom.xml:77, zheng-cms/zheng-cms-web/pom.xml:100, zheng-api/zheng-api-server/pom.xml:100, zheng-oss/zheng-oss-admin/pom.xml:89 |
Summary
The zheng project utilizes a robust and conventional build-time configuration strategy powered by Apache Maven. By defining environment-specific profiles (dev, test, prod) and leveraging resource filtering, the project ensures that each module is built with the correct configuration for its intended environment. This method promotes a clean separation of concerns and simplifies the deployment process across the entire application landscape.