This topic explains how to use Nacos Spring SDK.

Get the SDK

To get Nacos Spring SDK, add the following configuration to the pom.xml file in the Maven project.



  1. Add @EnableNacosConfig annotation to enable the configuration management service of Nacos Spring. Use @NacosPropertySource to load the configuration source with the dataId of, and turn on automatic update.

    // The endpoint and namespace can be found in the namespace details. We recommend that you use the accessKey and secretKey of the RAM account.
    @EnableNacosConfig(globalProperties = @NacosProperties(endpoint = "${endpoint}", namespace = "${namespace}",
    accessKey = "${accessKey}", secretKey = "${secretKey}"))
    @NacosPropertySource(dataId = "", autoRefreshed = true)
    public class NacosConfiguration {
  2. Set the value of the properties with the @NacosValue annotation of Nacos.

    public class ConfigController {
        @NacosValue("${connectTimeoutInMills:5000}", autoRefreshed = true)
        private int connectTimeoutInMills;
        @RequestMapping(value = "/get", method = GET)
        public int get() {
            return connectTimeoutInMills;
  3. Open the ACM console and create a new configuration under the corresponding namespace.

    • Data ID:

    • Select Properties for the configuration format, and put the specific key-value pairs in the configuration body:


    For the complete sample code, see nacos-spring-config-example.

Related documents