All Products
Search
Document Center

Implement configuration management

Last Updated: Aug 12, 2019

This topic describes how to connect your Spring Cloud applications to ACM and use ACM to manage their configurations.

Why is ACM used?

Application Configuration Management (ACM) is a configuration management product of Alibaba Cloud, which is a commercial version of open source Nacos configuration management.

Compared with other similar products, ACM offers certain advantages.For more information, see ACM product comparison.

Local development

Spring Cloud Alicloud ACM implements the integration of ACM with Spring Cloud framework and supports the injection of native Spring configurations.

Preparation

  • Download, start, and configure the lightweight configuration center.

    To facilitate local development, EDAS provides a lightweight configuration center that has the basic features of the EDAS service registry.You can deploy the applications developed based on the lightweight configuration center to EDAS without making any modifications to code or configurations.

    For more information about how to download, start, and configure the lightweight configuration center, see Configure a lightweight configuration center.The latest version is recommended.

  • Log on to the console of the lightweight configuration center. In the left-side navigation pane, click Configuration List. On the Configuration List page, click Add. On the Create Configuration page, enter the following information.

    • Group: DEFAULT_GROUP
    • DataId: acm-example.properties
    • Content: user.id=amctest

Use ACM for configuration management

  1. Create a Maven project named acm-example.

  2. The following takes Spring Boot 2.0.6 RELEASE and Spring Cloud Finchley.SR1 as an example. Add the following dependencies to the pom.xml file.

    1. <parent>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-starter-parent</artifactId>
    4. <version>2.0.6.RELEASE</version>
    5. <relativePath/>
    6. </parent>
    7. <dependencies>
    8. <dependency>
    9. <groupId>org.springframework.cloud</groupId>
    10. <artifactId>spring-cloud-starter-alicloud-acm</artifactId>
    11. <version>0.2.1.RELEASE</version>
    12. </dependency>
    13. <dependency>
    14. <groupId>org.springframework.boot</groupId>
    15. <artifactId>spring-boot-starter-web</artifactId>
    16. </dependency>
    17. </dependencies>
    18. <dependencyManagement>
    19. <dependencies>
    20. <dependency>
    21. <groupId>org.springframework.cloud</groupId>
    22. <artifactId>spring-cloud-dependencies</artifactId>
    23. <version>Finchley.SR1</version>
    24. <type>pom</type>
    25. <scope>import</scope>
    26. </dependency>
    27. </dependencies>
    28. </dependencyManagement>

    If you need to use Spring Boot 1.x, use Spring Boot 1.5.x, Spring Cloud Edgware, and Spring Cloud Alibaba 0.1.1. RELEASE.

    Note: Spring Boot 1.x will expire in August 2019, so we recommend that you use a later version to develop applications.

  3. Develop the startup class AcmExampleApplication of acm-example.

    1. @SpringBootApplication
    2. public class AcmExampleApplication {
    3. public static void main(String[] args) {
    4. SpringApplication.run(AcmExampleApplication.class, args);
    5. }
    6. }
  4. Create a simple controller and specify a UserId from the key in the configuration file named user.id.

    1. @RestController
    2. public class EchoController {
    3. @Value("${user.id}")
    4. private String userId;
    5. @RequestMapping(value = "/")
    6. public String echo() {
    7. return userId;
    8. }
    9. }
  5. Add the following configuration to the bootstrap.properties file and specify the EDAS lightweight configuration center as the registry.

    where, 127.0.0.1 is the address of the lightweight configuration center, which must be changed to the corresponding IP address if your lightweight configuration center is deployed on another instance.The lightweight configuration center does not support port modification, so port 8080 must be used.

    1. spring.application.name=acm-example
    2. server.port=18081
    3. spring.cloud.alicloud.acm.server-list=127.0.0.1
    4. spring.cloud.alicloud.acm.server-port=8080
  6. Execute the main function in the startup class AcmExampleApplication to enable the service.

Result verification

In your browser, enter the address http://127.0.0.1:18081/. The value acmtest is returned, which indicates the value of user.id you configured in the lightweight configuration center.

Deploy applications to EDAS

ACM is designed for migrating applications from the development environment to EDAS. It allows you to directly deploy applications to EDAS without any code or configuration modifications.

  1. Add the following configuration to the pom.xml file of acm-example. Then, run mvn clean package to package native programs into executable JAR packages.

    1. <build>
    2. <plugins>
    3. <plugin>
    4. <groupId>org.springframework.boot</groupId>
    5. <artifactId>spring-boot-maven-plugin</artifactId>
    6. </plugin>
    7. </plugins>
    8. </build>
  2. Deploy applications based on the appropriate documents for the corresponding cluster types.

Reference configuration items

Configuration item Key Default value Description
Extension spring.cloud.alicloud.acm.file-extension properties Indicates the configuration file extension, typically being properties or yaml
Timeout spring.cloud.alicloud.acm.timeout 3000 Indicates the timeout period for configuration retrieval
Refresh or not spring.cloud.alicloud.acm.refresh-enabled true Indicates whether the Spring context is to be refreshed when the configuration changes
Endpoint spring.cloud.alicloud.acm.endpoint None For more information, see ACM-SDK documentation.
Namespace spring.cloud.alicloud.acm.namespace None For more information, see ACM-SDK documentation.
RAM role spring.cloud.alicloud.acm.ram-role-name None For more information, see ACM-SDK documentation.

FAQ

  1. What is the relationship between ACM and EDAS?

    A: ACM is an independent Alibaba Cloud product and EDAS can provide a runtime environment for applications using ACM.