Skip to main content

Unified Configuration Center - Web Application Edition

Demonstrates using a unified configuration center in a web application. For more usage, refer to dawdler-client-plug-config-center-consul.

1. Download and Run​

Download the sample dawdler-tutorial.zip.

After extracting it, go into the conf-center-consul-single-web directory.

Start consul and configure dawdler-config.yml.

Run the main method of UserWebApplication.java.

@DawdlerBootApplication
public class UserWebApplication {
public static void main(String[] args) throws Throwable {
DawdlerWebApplication.run(UserWebApplication.class, args);
}
}

1.1 Configuration Files​

For the configuration related to the FieldConfig annotation, refer to dawdler-config-center-core.

For consul installation and configuration, refer to dawdler-config-center-consul-core.

1.2 Configuration in consul​

The configuration used by the example is as follows:

Create the node /testConfig
with the following content:

path: /test/config

Create the node /paymentConfig

with the following content:

paymentUrl: https://api.payment.com/pay
paymentKey: 202303031
paymentSecret: test

1.3 Running as a Jar​

Run

mvn clean package

to get conf-center-consul-single-web-0.0.1-jdk25-SNAPSHOT-all.jar

Then run

java -jar conf-center-consul-single-web-0.0.1-jdk25-SNAPSHOT-all.jar

1.4 Verification​

After startup, visit http://localhost:8085/user/getPath and http://localhost:8085/user/getPaymentConfig.