or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

audit.mdbuiltin-endpoints.mdendpoints.mdhealth.mdindex.mdinfo.mdmetrics.md

info.mddocs/

0

# Application Information

1

2

Spring Boot Actuator's info system provides a way to contribute application metadata, build information, git details, and environment information accessible via the info endpoint.

3

4

## Capabilities

5

6

### Core Info API

7

8

Basic interfaces for contributing application information.

9

10

```java { .api }

11

/**

12

* Strategy interface used to contribute Info to the response of the InfoEndpoint

13

*/

14

public interface InfoContributor {

15

/**

16

* Contribute info to the given Info.Builder instance

17

* @param builder the builder instance to contribute to

18

*/

19

void contribute(Info.Builder builder);

20

}

21

22

/**

23

* Carries information about the application

24

*/

25

public final class Info {

26

public Map<String, Object> getDetails();

27

28

/**

29

* Builder for Info instances

30

*/

31

public static final class Builder {

32

/**

33

* Associate the specified key/value pair

34

*/

35

public Builder withDetail(String key, Object value);

36

37

/**

38

* Associate all key/value pairs from the specified map

39

*/

40

public Builder withDetails(Map<String, Object> details);

41

42

/**

43

* Build the Info instance

44

*/

45

public Info build();

46

}

47

}

48

```

49

50

**Usage Example:**

51

52

```java

53

@Component

54

public class CustomInfoContributor implements InfoContributor {

55

56

private final ApplicationProperties applicationProperties;

57

58

public CustomInfoContributor(ApplicationProperties applicationProperties) {

59

this.applicationProperties = applicationProperties;

60

}

61

62

@Override

63

public void contribute(Info.Builder builder) {

64

builder.withDetail("app", Map.of(

65

"name", applicationProperties.getName(),

66

"version", applicationProperties.getVersion(),

67

"description", applicationProperties.getDescription(),

68

"encoding", StandardCharsets.UTF_8.name(),

69

"java", Map.of(

70

"source", System.getProperty("java.version"),

71

"target", System.getProperty("java.specification.version")

72

)

73

))

74

.withDetail("team", "Development Team")

75

.withDetail("contact", "dev-team@company.com");

76

}

77

}

78

```

79

80

### Info Endpoint

81

82

Built-in endpoint for exposing application information.

83

84

```java { .api }

85

/**

86

* Endpoint to expose application information

87

*/

88

@Endpoint(id = "info")

89

public class InfoEndpoint {

90

public InfoEndpoint(InfoContributorRegistry registry);

91

92

@ReadOperation

93

public Map<String, Object> info();

94

}

95

96

/**

97

* Registry of InfoContributor instances

98

*/

99

public interface InfoContributorRegistry extends NamedContributorRegistry<InfoContributor> {

100

void registerContributor(String name, InfoContributor contributor);

101

InfoContributor unregisterContributor(String name);

102

InfoContributor getContributor(String name);

103

}

104

```

105

106

### Build Information Contributor

107

108

Contributes build information from build-info.properties file.

109

110

```java { .api }

111

/**

112

* InfoContributor that exposes build information

113

*/

114

public class BuildInfoContributor implements InfoContributor {

115

public BuildInfoContributor(BuildProperties properties);

116

117

@Override

118

public void contribute(Info.Builder builder);

119

}

120

121

/**

122

* Provides access to build information

123

*/

124

public class BuildProperties extends InfoProperties {

125

public BuildProperties(Properties entries);

126

127

/**

128

* Version of the application

129

*/

130

public String getVersion();

131

132

/**

133

* Timestamp when the application was built

134

*/

135

public Instant getTime();

136

137

/**

138

* Artifact ID of the application

139

*/

140

public String getArtifact();

141

142

/**

143

* Group ID of the application

144

*/

145

public String getGroup();

146

147

/**

148

* Name of the application

149

*/

150

public String getName();

151

152

/**

153

* Get custom property by key

154

*/

155

public String get(String key);

156

}

157

```

158

159

**Usage Example:**

160

161

```java

162

@Configuration

163

public class InfoConfiguration {

164

165

@Bean

166

@ConditionalOnResource(resources = "classpath:META-INF/build-info.properties")

167

public BuildProperties buildProperties() throws IOException {

168

Properties properties = new Properties();

169

try (InputStream inputStream = getClass().getResourceAsStream("/META-INF/build-info.properties")) {

170

properties.load(inputStream);

171

}

172

return new BuildProperties(properties);

173

}

174

175

@Bean

176

@ConditionalOnBean(BuildProperties.class)

177

public BuildInfoContributor buildInfoContributor(BuildProperties buildProperties) {

178

return new BuildInfoContributor(buildProperties);

179

}

180

}

181

```

182

183

### Git Information Contributor

184

185

Contributes Git information from git.properties file.

186

187

```java { .api }

188

/**

189

* InfoContributor that exposes Git information

190

*/

191

public class GitInfoContributor implements InfoContributor {

192

public GitInfoContributor(GitProperties properties);

193

public GitInfoContributor(GitProperties properties, InfoContributorMode mode);

194

195

@Override

196

public void contribute(Info.Builder builder);

197

198

/**

199

* Modes for git info contribution

200

*/

201

public enum InfoContributorMode {

202

/**

203

* Expose only basic git information

204

*/

205

SIMPLE,

206

/**

207

* Expose full git information

208

*/

209

FULL

210

}

211

}

212

213

/**

214

* Provides access to Git information

215

*/

216

public class GitProperties extends InfoProperties {

217

public GitProperties(Properties entries);

218

219

/**

220

* SHA-1 of the commit

221

*/

222

public String getShortCommitId();

223

224

/**

225

* Full SHA-1 of the commit

226

*/

227

public String getCommitId();

228

229

/**

230

* Name of the branch

231

*/

232

public String getBranch();

233

234

/**

235

* Timestamp of the commit

236

*/

237

public Instant getCommitTime();

238

239

/**

240

* Commit message

241

*/

242

public String getCommitMessage();

243

244

/**

245

* Get custom git property by key

246

*/

247

public String get(String key);

248

}

249

```

250

251

### Environment Information Contributor

252

253

Contributes environment properties information.

254

255

```java { .api }

256

/**

257

* InfoContributor that exposes environment information

258

*/

259

public class EnvironmentInfoContributor implements InfoContributor {

260

public EnvironmentInfoContributor(Environment environment);

261

262

@Override

263

public void contribute(Info.Builder builder);

264

}

265

```

266

267

**Usage Example:**

268

269

```java

270

@Component

271

public class EnvironmentInfoContributor implements InfoContributor {

272

273

private final Environment environment;

274

275

public EnvironmentInfoContributor(Environment environment) {

276

this.environment = environment;

277

}

278

279

@Override

280

public void contribute(Info.Builder builder) {

281

Map<String, Object> envDetails = new HashMap<>();

282

283

// Add active profiles

284

envDetails.put("activeProfiles", Arrays.asList(environment.getActiveProfiles()));

285

286

// Add custom environment properties

287

envDetails.put("server.port", environment.getProperty("server.port", "8080"));

288

envDetails.put("spring.application.name",

289

environment.getProperty("spring.application.name", "unknown"));

290

291

builder.withDetail("environment", envDetails);

292

}

293

}

294

```

295

296

### System Information Contributors

297

298

Contributors for Java runtime and operating system information.

299

300

```java { .api }

301

/**

302

* InfoContributor that exposes Java information

303

*/

304

public class JavaInfoContributor implements InfoContributor {

305

@Override

306

public void contribute(Info.Builder builder);

307

}

308

309

/**

310

* InfoContributor that exposes operating system information

311

*/

312

public class OsInfoContributor implements InfoContributor {

313

@Override

314

public void contribute(Info.Builder builder);

315

}

316

317

/**

318

* InfoContributor that exposes process information

319

*/

320

public class ProcessInfoContributor implements InfoContributor {

321

@Override

322

public void contribute(Info.Builder builder);

323

}

324

```

325

326

**Usage Example:**

327

328

```java

329

@Configuration

330

public class SystemInfoConfiguration {

331

332

@Bean

333

public JavaInfoContributor javaInfoContributor() {

334

return new JavaInfoContributor();

335

}

336

337

@Bean

338

public OsInfoContributor osInfoContributor() {

339

return new OsInfoContributor();

340

}

341

342

@Bean

343

public ProcessInfoContributor processInfoContributor() {

344

return new ProcessInfoContributor();

345

}

346

}

347

```

348

349

### SSL Information Contributor

350

351

Contributes SSL configuration information.

352

353

```java { .api }

354

/**

355

* InfoContributor that exposes SSL information

356

*/

357

public class SslInfoContributor implements InfoContributor {

358

public SslInfoContributor(SslBundles sslBundles);

359

360

@Override

361

public void contribute(Info.Builder builder);

362

}

363

```

364

365

### Base Info Properties Class

366

367

Base class for property-based info contributors.

368

369

```java { .api }

370

/**

371

* Base class for info properties

372

*/

373

public abstract class InfoProperties implements Iterable<InfoProperties.Entry> {

374

375

/**

376

* Get property value by key

377

*/

378

public String get(String key);

379

380

/**

381

* Get property value by key with default

382

*/

383

public String get(String key, String defaultValue);

384

385

/**

386

* Get all property keys

387

*/

388

public Set<String> getKeys();

389

390

@Override

391

public Iterator<Entry> iterator();

392

393

/**

394

* Entry representing a key-value pair

395

*/

396

public static final class Entry {

397

public String getKey();

398

public String getValue();

399

}

400

}

401

```

402

403

### Custom Info Contributors Examples

404

405

Advanced patterns for custom info contributors.

406

407

**Usage Example:**

408

409

```java

410

@Component

411

public class DatabaseInfoContributor implements InfoContributor {

412

413

private final DataSource dataSource;

414

415

public DatabaseInfoContributor(DataSource dataSource) {

416

this.dataSource = dataSource;

417

}

418

419

@Override

420

public void contribute(Info.Builder builder) {

421

try (Connection connection = dataSource.getConnection()) {

422

DatabaseMetaData metaData = connection.getMetaData();

423

424

Map<String, Object> dbInfo = Map.of(

425

"name", metaData.getDatabaseProductName(),

426

"version", metaData.getDatabaseProductVersion(),

427

"driver", Map.of(

428

"name", metaData.getDriverName(),

429

"version", metaData.getDriverVersion()

430

),

431

"url", metaData.getURL(),

432

"schema", connection.getSchema()

433

);

434

435

builder.withDetail("database", dbInfo);

436

} catch (SQLException e) {

437

builder.withDetail("database", Map.of("error", e.getMessage()));

438

}

439

}

440

}

441

442

@Component

443

public class DependencyInfoContributor implements InfoContributor {

444

445

@Override

446

public void contribute(Info.Builder builder) {

447

Map<String, Object> dependencies = new HashMap<>();

448

449

// Spring Boot version

450

String springBootVersion = SpringBootVersion.getVersion();

451

if (springBootVersion != null) {

452

dependencies.put("spring-boot", springBootVersion);

453

}

454

455

// JVM information

456

dependencies.put("java", Map.of(

457

"version", System.getProperty("java.version"),

458

"vendor", System.getProperty("java.vendor"),

459

"vm", Map.of(

460

"name", System.getProperty("java.vm.name"),

461

"version", System.getProperty("java.vm.version")

462

)

463

));

464

465

// Custom library versions

466

dependencies.put("libraries", Map.of(

467

"jackson", getJacksonVersion(),

468

"slf4j", getSLF4JVersion()

469

));

470

471

builder.withDetail("dependencies", dependencies);

472

}

473

474

private String getJacksonVersion() {

475

try {

476

return com.fasterxml.jackson.core.Version.unknownVersion().toString();

477

} catch (Exception e) {

478

return "unknown";

479

}

480

}

481

482

private String getSLF4JVersion() {

483

try {

484

return org.slf4j.impl.StaticLoggerBinder.REQUESTED_API_VERSION;

485

} catch (Exception e) {

486

return "unknown";

487

}

488

}

489

}

490

```