or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

clustering.mdconfiguration.mdextensions.mdindex.mdmetadata.mdregistry.mdrpc-core.mdserialization.mdspring-boot.md

configuration.mddocs/

0

# Configuration and Bootstrap

1

2

Apache Dubbo provides comprehensive configuration management through programmatic APIs, declarative configuration, and Spring Boot integration. The configuration system supports application lifecycle management, service definitions, and runtime behavior customization.

3

4

## Capabilities

5

6

### Application Bootstrap

7

8

The `DubboBootstrap` class provides the main entry point for programmatic Dubbo initialization and lifecycle management.

9

10

```java { .api }

11

/**

12

* Main bootstrap class for programmatic Dubbo initialization

13

*/

14

public class DubboBootstrap {

15

/** Get singleton bootstrap instance */

16

public static DubboBootstrap getInstance();

17

18

/** Configure application settings */

19

public DubboBootstrap application(ApplicationConfig application);

20

21

/** Add protocol configuration */

22

public DubboBootstrap protocol(ProtocolConfig protocol);

23

24

/** Add multiple protocol configurations */

25

public DubboBootstrap protocols(List<ProtocolConfig> protocols);

26

27

/** Add registry configuration */

28

public DubboBootstrap registry(RegistryConfig registry);

29

30

/** Add multiple registry configurations */

31

public DubboBootstrap registries(List<RegistryConfig> registries);

32

33

/** Add service configuration */

34

public DubboBootstrap service(ServiceConfig<?> service);

35

36

/** Add reference configuration */

37

public DubboBootstrap reference(ReferenceConfig<?> reference);

38

39

/** Add provider default configuration */

40

public DubboBootstrap provider(ProviderConfig provider);

41

42

/** Add consumer default configuration */

43

public DubboBootstrap consumer(ConsumerConfig consumer);

44

45

/** Add module configuration */

46

public DubboBootstrap module(ModuleConfig module);

47

48

/** Add configuration center */

49

public DubboBootstrap configCenter(ConfigCenterConfig configCenter);

50

51

/** Add metadata configuration */

52

public DubboBootstrap metadataReport(MetadataReportConfig metadataReport);

53

54

/** Start Dubbo framework */

55

public DubboBootstrap start();

56

57

/** Stop Dubbo framework */

58

public DubboBootstrap stop();

59

60

/** Check if Dubbo is started */

61

public boolean isStarted();

62

63

/** Await until Dubbo is ready */

64

public DubboBootstrap await();

65

}

66

```

67

68

**Usage Examples:**

69

70

```java

71

import org.apache.dubbo.config.bootstrap.DubboBootstrap;

72

import org.apache.dubbo.config.*;

73

74

// Complete bootstrap setup

75

DubboBootstrap bootstrap = DubboBootstrap.getInstance();

76

77

// Configure application

78

ApplicationConfig app = new ApplicationConfig("my-dubbo-app");

79

app.setVersion("1.0.0");

80

app.setOwner("development-team");

81

82

// Configure protocol

83

ProtocolConfig protocol = new ProtocolConfig();

84

protocol.setName("dubbo");

85

protocol.setPort(20880);

86

protocol.setThreads(200);

87

88

// Configure registry

89

RegistryConfig registry = new RegistryConfig();

90

registry.setAddress("zookeeper://127.0.0.1:2181");

91

registry.setUsername("admin");

92

registry.setPassword("secret");

93

94

// Bootstrap with configurations

95

bootstrap.application(app)

96

.protocol(protocol)

97

.registry(registry)

98

.start();

99

100

// Graceful shutdown

101

Runtime.getRuntime().addShutdownHook(new Thread(bootstrap::stop));

102

```

103

104

### Application Configuration

105

106

Core application-level configuration including identity, metadata, and runtime behavior.

107

108

```java { .api }

109

/**

110

* Application-level configuration

111

*/

112

public class ApplicationConfig extends AbstractConfig {

113

public ApplicationConfig();

114

public ApplicationConfig(String name);

115

116

/** Set application name */

117

public void setName(String name);

118

public String getName();

119

120

/** Set application version */

121

public void setVersion(String version);

122

public String getVersion();

123

124

/** Set application owner */

125

public void setOwner(String owner);

126

public String getOwner();

127

128

/** Set organization name */

129

public void setOrganization(String organization);

130

public String getOrganization();

131

132

/** Set application architecture layer */

133

public void setArchitecture(String architecture);

134

public String getArchitecture();

135

136

/** Set application environment */

137

public void setEnvironment(String environment);

138

public String getEnvironment();

139

140

/** Set compiler for dynamic proxy generation */

141

public void setCompiler(String compiler);

142

public String getCompiler();

143

144

/** Set logger implementation */

145

public void setLogger(String logger);

146

public String getLogger();

147

148

/** Set dump directory for thread dumps */

149

public void setDumpDirectory(String dumpDirectory);

150

public String getDumpDirectory();

151

152

/** Enable/disable QoS server */

153

public void setQosEnable(Boolean qosEnable);

154

public Boolean getQosEnable();

155

156

/** Set QoS server port */

157

public void setQosPort(Integer qosPort);

158

public Integer getQosPort();

159

160

/** Accept external QoS connections */

161

public void setQosAcceptForeignIp(Boolean qosAcceptForeignIp);

162

public Boolean getQosAcceptForeignIp();

163

}

164

```

165

166

### Protocol Configuration

167

168

Configuration for communication protocols including ports, threading, and serialization.

169

170

```java { .api }

171

/**

172

* Protocol configuration for communication layer

173

*/

174

public class ProtocolConfig extends AbstractConfig {

175

public ProtocolConfig();

176

public ProtocolConfig(String name);

177

public ProtocolConfig(String name, int port);

178

179

/** Set protocol name (dubbo, rest, grpc, etc.) */

180

public void setName(String name);

181

public String getName();

182

183

/** Set protocol port */

184

public void setPort(int port);

185

public int getPort();

186

187

/** Set bind host */

188

public void setHost(String host);

189

public String getHost();

190

191

/** Set thread pool size */

192

public void setThreads(int threads);

193

public int getThreads();

194

195

/** Set IO thread pool size */

196

public void setIothreads(int iothreads);

197

public int getIothreads();

198

199

/** Set thread pool type */

200

public void setThreadpool(String threadpool);

201

public String getThreadpool();

202

203

/** Set accept connections limit */

204

public void setAccepts(int accepts);

205

public int getAccepts();

206

207

/** Set payload limit in bytes */

208

public void setPayload(int payload);

209

public int getPayload();

210

211

/** Set codec type */

212

public void setCodec(String codec);

213

public String getCodec();

214

215

/** Set compression type */

216

public void setCompression(String compression);

217

public String getCompression();

218

219

/** Set serialization type */

220

public void setSerialization(String serialization);

221

public String getSerialization();

222

223

/** Set network transport */

224

public void setTransporter(String transporter);

225

public String getTransporter();

226

227

/** Set channel handler */

228

public void setDispatcher(String dispatcher);

229

public String getDispatcher();

230

231

/** Set heartbeat interval */

232

public void setHeartbeat(int heartbeat);

233

public int getHeartbeat();

234

235

/** Enable SSL */

236

public void setSslEnabled(Boolean sslEnabled);

237

public Boolean getSslEnabled();

238

}

239

```

240

241

### Registry Configuration

242

243

Configuration for service discovery backends including connection details and behavior.

244

245

```java { .api }

246

/**

247

* Registry configuration for service discovery

248

*/

249

public class RegistryConfig extends AbstractConfig {

250

public RegistryConfig();

251

public RegistryConfig(String address);

252

253

/** Set registry address */

254

public void setAddress(String address);

255

public String getAddress();

256

257

/** Set registry protocol */

258

public void setProtocol(String protocol);

259

public String getProtocol();

260

261

/** Set registry port */

262

public void setPort(int port);

263

public int getPort();

264

265

/** Set username for authentication */

266

public void setUsername(String username);

267

public String getUsername();

268

269

/** Set password for authentication */

270

public void setPassword(String password);

271

public String getPassword();

272

273

/** Set connection timeout */

274

public void setTimeout(int timeout);

275

public int getTimeout();

276

277

/** Set session timeout */

278

public void setSession(int session);

279

public int getSession();

280

281

/** Set registry file cache path */

282

public void setFile(String file);

283

public String getFile();

284

285

/** Enable/disable dynamic registration */

286

public void setDynamic(Boolean dynamic);

287

public Boolean getDynamic();

288

289

/** Enable/disable registry */

290

public void setRegister(Boolean register);

291

public Boolean getRegister();

292

293

/** Enable/disable subscription */

294

public void setSubscribe(Boolean subscribe);

295

public Boolean getSubscribe();

296

297

/** Set service group */

298

public void setGroup(String group);

299

public String getGroup();

300

301

/** Set service version */

302

public void setVersion(String version);

303

public String getVersion();

304

305

/** Set retry period for failed operations */

306

public void setRetryPeriod(int retryPeriod);

307

public int getRetryPeriod();

308

309

/** Enable/disable check on startup */

310

public void setCheck(Boolean check);

311

public Boolean getCheck();

312

}

313

```

314

315

### Service Configuration

316

317

Configuration for service providers including interface binding and behavior settings.

318

319

```java { .api }

320

/**

321

* Service provider configuration

322

* @param <T> Service interface type

323

*/

324

public class ServiceConfig<T> extends ServiceConfigBase<T> {

325

public ServiceConfig();

326

public ServiceConfig(Service service);

327

328

/** Set service interface class */

329

public void setInterface(Class<?> interfaceClass);

330

public void setInterface(String interfaceName);

331

public String getInterface();

332

333

/** Set service implementation reference */

334

public void setRef(T ref);

335

public T getRef();

336

337

/** Set service path */

338

public void setPath(String path);

339

public String getPath();

340

341

/** Export service (make it available for consumers) */

342

public synchronized void export();

343

344

/** Unexport service */

345

public synchronized void unexport();

346

347

/** Check if service is exported */

348

public boolean isExported();

349

350

/** Check if service is unexported */

351

public boolean isUnexported();

352

353

/** Set service version */

354

public void setVersion(String version);

355

public String getVersion();

356

357

/** Set service group */

358

public void setGroup(String group);

359

public String getGroup();

360

361

/** Enable/disable deprecated */

362

public void setDeprecated(Boolean deprecated);

363

public Boolean getDeprecated();

364

365

/** Set delay for service export (ms) */

366

public void setDelay(Integer delay);

367

public Integer getDelay();

368

369

/** Set service weight for load balancing */

370

public void setWeight(Integer weight);

371

public Integer getWeight();

372

373

/** Set document URL */

374

public void setDocument(String document);

375

public String getDocument();

376

377

/** Enable/disable dynamic registration */

378

public void setDynamic(Boolean dynamic);

379

public Boolean getDynamic();

380

381

/** Set access token for security */

382

public void setToken(String token);

383

public String getToken();

384

385

/** Set access log configuration */

386

public void setAccesslog(String accesslog);

387

public String getAccesslog();

388

389

/** Add method-specific configuration */

390

public void setMethods(List<MethodConfig> methods);

391

public List<MethodConfig> getMethods();

392

}

393

```

394

395

### Reference Configuration

396

397

Configuration for service consumers including interface references and invocation behavior.

398

399

```java { .api }

400

/**

401

* Service consumer reference configuration

402

* @param <T> Service interface type

403

*/

404

public class ReferenceConfig<T> extends ReferenceConfigBase<T> {

405

public ReferenceConfig();

406

public ReferenceConfig(Reference reference);

407

408

/** Set service interface class */

409

public void setInterface(Class<T> interfaceClass);

410

public void setInterface(String interfaceName);

411

public String getInterface();

412

413

/** Get service proxy instance */

414

public synchronized T get();

415

416

/** Destroy reference and release resources */

417

public synchronized void destroy();

418

419

/** Set service URL directly (bypass registry) */

420

public void setUrl(String url);

421

public String getUrl();

422

423

/** Set service version */

424

public void setVersion(String version);

425

public String getVersion();

426

427

/** Set service group */

428

public void setGroup(String group);

429

public String getGroup();

430

431

/** Set client type */

432

public void setClient(String client);

433

public String getClient();

434

435

/** Enable/disable generic invocation */

436

public void setGeneric(String generic);

437

public String getGeneric();

438

439

/** Enable/disable injvm optimization */

440

public void setInjvm(Boolean injvm);

441

public Boolean getInjvm();

442

443

/** Enable/disable lazy initialization */

444

public void setLazy(Boolean lazy);

445

public Boolean getLazy();

446

447

/** Enable/disable sticky sessions */

448

public void setSticky(Boolean sticky);

449

public Boolean getSticky();

450

451

/** Set reconnect interval */

452

public void setReconnect(String reconnect);

453

public String getReconnect();

454

455

/** Add method-specific configuration */

456

public void setMethods(List<MethodConfig> methods);

457

public List<MethodConfig> getMethods();

458

}

459

```

460

461

**Usage Examples:**

462

463

```java

464

// Service provider configuration

465

ServiceConfig<GreeterService> service = new ServiceConfig<>();

466

service.setInterface(GreeterService.class);

467

service.setRef(new GreeterServiceImpl());

468

service.setVersion("1.0.0");

469

service.setGroup("default");

470

service.setDelay(5000); // 5 second delay

471

service.export();

472

473

// Service consumer configuration

474

ReferenceConfig<GreeterService> reference = new ReferenceConfig<>();

475

reference.setInterface(GreeterService.class);

476

reference.setVersion("1.0.0");

477

reference.setGroup("default");

478

reference.setTimeout(3000);

479

reference.setRetries(2);

480

481

GreeterService greeter = reference.get();

482

String result = greeter.sayHello("World");

483

```

484

485

### Method Configuration

486

487

Fine-grained configuration for specific service methods.

488

489

```java { .api }

490

/**

491

* Method-level configuration for fine-grained control

492

*/

493

public class MethodConfig extends AbstractMethodConfig {

494

public MethodConfig();

495

public MethodConfig(Method method);

496

497

/** Set method name */

498

public void setName(String name);

499

public String getName();

500

501

/** Set method timeout (ms) */

502

public void setTimeout(Integer timeout);

503

public Integer getTimeout();

504

505

/** Set retry count */

506

public void setRetries(Integer retries);

507

public Integer getRetries();

508

509

/** Set load balancing algorithm */

510

public void setLoadbalance(String loadbalance);

511

public String getLoadbalance();

512

513

/** Enable/disable async invocation */

514

public void setAsync(Boolean async);

515

public Boolean getAsync();

516

517

/** Set async response handling */

518

public void setSent(Boolean sent);

519

public Boolean getSent();

520

521

/** Set max concurrent active requests */

522

public void setActives(Integer actives);

523

public Integer getActives();

524

525

/** Set execution limit per method */

526

public void setExecutes(Integer executes);

527

public Integer getExecutes();

528

529

/** Enable/disable deprecated */

530

public void setDeprecated(Boolean deprecated);

531

public Boolean getDeprecated();

532

533

/** Enable/disable sticky sessions */

534

public void setSticky(Boolean sticky);

535

public Boolean getSticky();

536

537

/** Enable/disable return value */

538

public void setReturn(Boolean isReturn);

539

public Boolean getReturn();

540

541

/** Set validation groups */

542

public void setValidation(String validation);

543

public String getValidation();

544

545

/** Add argument-specific configuration */

546

public void setArguments(List<ArgumentConfig> arguments);

547

public List<ArgumentConfig> getArguments();

548

}

549

550

/**

551

* Argument-level configuration

552

*/

553

public class ArgumentConfig extends AbstractConfig {

554

public ArgumentConfig();

555

public ArgumentConfig(Object argument);

556

557

/** Set argument index */

558

public void setIndex(Integer index);

559

public Integer getIndex();

560

561

/** Set argument type */

562

public void setType(String type);

563

public String getType();

564

565

/** Enable/disable callback */

566

public void setCallback(Boolean callback);

567

public Boolean getCallback();

568

}

569

```

570

571

### Provider and Consumer Defaults

572

573

Default configurations that apply to all services or references.

574

575

```java { .api }

576

/**

577

* Default configuration for service providers

578

*/

579

public class ProviderConfig extends AbstractServiceConfig {

580

public ProviderConfig();

581

582

/** Set default host */

583

public void setHost(String host);

584

public String getHost();

585

586

/** Set default port */

587

public void setPort(Integer port);

588

public Integer getPort();

589

590

/** Set default context path */

591

public void setContextpath(String contextpath);

592

public String getContextpath();

593

594

/** Set default thread pool */

595

public void setThreadpool(String threadpool);

596

public String getThreadpool();

597

598

/** Set default thread count */

599

public void setThreads(Integer threads);

600

public Integer getThreads();

601

602

/** Set default IO threads */

603

public void setIothreads(Integer iothreads);

604

public Integer getIothreads();

605

606

/** Set default connection limit */

607

public void setAccepts(Integer accepts);

608

public Integer getAccepts();

609

610

/** Set default payload size */

611

public void setPayload(Integer payload);

612

public Integer getPayload();

613

}

614

615

/**

616

* Default configuration for service consumers

617

*/

618

public class ConsumerConfig extends AbstractReferenceConfig {

619

public ConsumerConfig();

620

621

/** Set default timeout */

622

public void setTimeout(Integer timeout);

623

public Integer getTimeout();

624

625

/** Set default retries */

626

public void setRetries(Integer retries);

627

public Integer getRetries();

628

629

/** Set default load balancer */

630

public void setLoadbalance(String loadbalance);

631

public String getLoadbalance();

632

633

/** Enable/disable async by default */

634

public void setAsync(Boolean async);

635

public Boolean getAsync();

636

637

/** Set default connections per provider */

638

public void setConnections(Integer connections);

639

public Integer getConnections();

640

641

/** Enable/disable generic invocation */

642

public void setGeneric(String generic);

643

public String getGeneric();

644

645

/** Enable/disable check on startup */

646

public void setCheck(Boolean check);

647

public Boolean getCheck();

648

649

/** Set default proxy type */

650

public void setProxy(String proxy);

651

public String getProxy();

652

653

/** Set default owner */

654

public void setOwner(String owner);

655

public String getOwner();

656

}

657

```

658

659

### Configuration Centers

660

661

Configuration for external configuration management systems.

662

663

```java { .api }

664

/**

665

* Configuration center settings

666

*/

667

public class ConfigCenterConfig extends AbstractConfig {

668

public ConfigCenterConfig();

669

670

/** Set config center address */

671

public void setAddress(String address);

672

public String getAddress();

673

674

/** Set config center protocol */

675

public void setProtocol(String protocol);

676

public String getProtocol();

677

678

/** Set config center port */

679

public void setPort(Integer port);

680

public Integer getPort();

681

682

/** Set username */

683

public void setUsername(String username);

684

public String getUsername();

685

686

/** Set password */

687

public void setPassword(String password);

688

public String getPassword();

689

690

/** Set timeout */

691

public void setTimeout(Long timeout);

692

public Long getTimeout();

693

694

/** Set config group */

695

public void setGroup(String group);

696

public String getGroup();

697

698

/** Set config namespace */

699

public void setNamespace(String namespace);

700

public String getNamespace();

701

702

/** Set cluster name */

703

public void setCluster(String cluster);

704

public String getCluster();

705

706

/** Enable/disable check on startup */

707

public void setCheck(Boolean check);

708

public Boolean getCheck();

709

710

/** Set config file */

711

public void setConfigFile(String configFile);

712

public String getConfigFile();

713

714

/** Set application config file */

715

public void setAppConfigFile(String appConfigFile);

716

public String getAppConfigFile();

717

718

/** Set highest priority */

719

public void setHighestPriority(Boolean highestPriority);

720

public Boolean getHighestPriority();

721

}

722

```

723

724

### Configuration Builders

725

726

Fluent API builders for configuration objects.

727

728

```java { .api }

729

/**

730

* Builder for ApplicationConfig

731

*/

732

public class ApplicationBuilder {

733

public static ApplicationBuilder newBuilder();

734

public ApplicationBuilder name(String name);

735

public ApplicationBuilder version(String version);

736

public ApplicationBuilder owner(String owner);

737

public ApplicationBuilder organization(String organization);

738

public ApplicationBuilder architecture(String architecture);

739

public ApplicationBuilder environment(String environment);

740

public ApplicationBuilder compiler(String compiler);

741

public ApplicationBuilder logger(String logger);

742

public ApplicationBuilder qosEnable(Boolean qosEnable);

743

public ApplicationBuilder qosPort(Integer qosPort);

744

public ApplicationConfig build();

745

}

746

747

/**

748

* Builder for ProtocolConfig

749

*/

750

public class ProtocolBuilder {

751

public static ProtocolBuilder newBuilder();

752

public ProtocolBuilder name(String name);

753

public ProtocolBuilder port(int port);

754

public ProtocolBuilder host(String host);

755

public ProtocolBuilder threads(int threads);

756

public ProtocolBuilder payload(int payload);

757

public ProtocolBuilder serialization(String serialization);

758

public ProtocolConfig build();

759

}

760

```

761

762

**Usage Examples:**

763

764

```java

765

import org.apache.dubbo.config.bootstrap.builders.*;

766

767

// Using builders for fluent configuration

768

ApplicationConfig app = ApplicationBuilder.newBuilder()

769

.name("my-app")

770

.version("1.0.0")

771

.owner("dev-team")

772

.qosEnable(true)

773

.qosPort(22222)

774

.build();

775

776

ProtocolConfig protocol = ProtocolBuilder.newBuilder()

777

.name("dubbo")

778

.port(20880)

779

.threads(200)

780

.serialization("hessian2")

781

.build();

782

783

RegistryConfig registry = RegistryBuilder.newBuilder()

784

.address("zookeeper://127.0.0.1:2181")

785

.timeout(5000)

786

.check(true)

787

.build();

788

```