Dynamic configuration primarily uses annotations to identify configuration classes. This topic describes how to overwrite annotation configurations for more flexible initialization of dynamic configuration classes.
For information about how to configure a dynamic configuration class exclusively with annotations, see Getting started with dynamic configuration.
Overwrite annotation configurations
You can register a configuration class with the dynamic configuration client in two ways:
You can directly register the configuration class with all its annotations.
DistributedResourceManager#register(Object resourceObject);You can register a configuration class instance and pass configuration items to overwrite its annotations.
DistributedResourceManager#register(Object resourceObject, Config config);`Config` contains all the properties of `@DObject`. Values set in `Config` overwrite the annotation configurations.
Advanced uses of property annotations
By default, when the client starts, it synchronously loads configuration values from the server. If you want server-side values to take effect only at runtime, or if you do not want the client to sync values at startup, use the `DependencyLevel` in `@DAttribute` to define the dependency level for the property.
The following property dependency levels are available:
Dependency level | Description |
NONE | No dependency. Server-side values are not loaded at startup. With this level, the client only accepts configuration pushes from the server during runtime. |
ASYNC | Asynchronous update. Server-side values are loaded asynchronously at startup. The load result is ignored. |
WEAK | Weak dependency. Server-side pushed values are loaded synchronously at startup. If the server is unavailable, the application starts normally. After the server becomes active, the client uses heartbeat detection to pull the server-side values again. |
STRONG | Strong dependency. Server-side values are loaded synchronously at startup. If no value is set on the server, the value from the code initialization is used. If a request to get data from the server is abnormal or if the client fails to set the value, an exception is thrown and the application fails to start. |
EAGER | Strongest dependency. Server-side values must be pulled at startup. If the server has not pushed a value, an exception is thrown and the application fails to start. |