or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

bean-validation.mdbootstrap-configuration.mdconstraints.mdcontainer-validation.mdcustom-constraints.mdindex.mdmetadata.mdmethod-validation.mdvalidation-groups.md

bootstrap-configuration.mddocs/

0

# Bootstrap and Configuration

1

2

Core API for setting up and configuring the validation framework, providing entry points for creating validators and customizing the validation environment.

3

4

## Capabilities

5

6

### Validation Entry Point

7

8

Static entry point for bootstrapping Jakarta Validation with default or custom provider configurations.

9

10

```java { .api }

11

/**

12

* Bootstrap entry point for Jakarta Validation

13

*/

14

class Validation {

15

/**

16

* Build a ValidatorFactory using the default validation provider

17

* @return ValidatorFactory instance

18

*/

19

static ValidatorFactory buildDefaultValidatorFactory();

20

21

/**

22

* Get a generic bootstrap instance for provider-agnostic configuration

23

* @return GenericBootstrap instance

24

*/

25

static GenericBootstrap byDefaultProvider();

26

27

/**

28

* Get a provider-specific bootstrap for a particular validation provider

29

* @param providerType the validation provider class

30

* @return provider-specific bootstrap instance

31

*/

32

static <T extends Configuration<T>, U extends ValidationProvider<T>>

33

ProviderSpecificBootstrap<T> byProvider(Class<U> providerType);

34

}

35

```

36

37

**Usage Examples:**

38

39

```java

40

import jakarta.validation.Validation;

41

import jakarta.validation.ValidatorFactory;

42

43

// Default setup - simplest approach

44

ValidatorFactory factory = Validation.buildDefaultValidatorFactory();

45

Validator validator = factory.getValidator();

46

47

// Provider-agnostic bootstrap

48

GenericBootstrap bootstrap = Validation.byDefaultProvider();

49

Configuration<?> config = bootstrap.configure();

50

ValidatorFactory customFactory = config.buildValidatorFactory();

51

```

52

53

### Validator Factory

54

55

Factory interface for creating validators and accessing validation configuration components.

56

57

```java { .api }

58

/**

59

* Factory for Validator instances and access to validation configuration

60

* Implementations must be thread-safe

61

*/

62

interface ValidatorFactory extends AutoCloseable {

63

/**

64

* Get a Validator instance for validation operations

65

* @return thread-safe Validator instance

66

*/

67

Validator getValidator();

68

69

/**

70

* Get a ValidatorContext for creating customized validators

71

* @return ValidatorContext for customization

72

*/

73

ValidatorContext usingContext();

74

75

/**

76

* Get the MessageInterpolator used by this factory

77

* @return MessageInterpolator instance

78

*/

79

MessageInterpolator getMessageInterpolator();

80

81

/**

82

* Get the TraversableResolver used by this factory

83

* @return TraversableResolver instance

84

*/

85

TraversableResolver getTraversableResolver();

86

87

/**

88

* Get the ConstraintValidatorFactory used by this factory

89

* @return ConstraintValidatorFactory instance

90

*/

91

ConstraintValidatorFactory getConstraintValidatorFactory();

92

93

/**

94

* Get the ParameterNameProvider used by this factory

95

* @return ParameterNameProvider instance

96

*/

97

ParameterNameProvider getParameterNameProvider();

98

99

/**

100

* Get the ClockProvider used by this factory

101

* @return ClockProvider instance

102

*/

103

ClockProvider getClockProvider();

104

105

/**

106

* Unwrap the ValidatorFactory to a specific type

107

* @param type target type to unwrap to

108

* @return unwrapped instance

109

* @throws ValidationException if unwrapping is not supported

110

*/

111

<T> T unwrap(Class<T> type);

112

113

/**

114

* Close the ValidatorFactory and release resources

115

*/

116

void close();

117

}

118

```

119

120

### Configuration Interface

121

122

Generic configuration interface for customizing validation behavior before building a ValidatorFactory.

123

124

```java { .api }

125

/**

126

* Configuration interface for setting up validation before building ValidatorFactory

127

* @param <T> type of the configuration implementation

128

*/

129

interface Configuration<T extends Configuration<T>> {

130

/**

131

* Ignore META-INF/validation.xml configuration

132

* @return this configuration instance

133

*/

134

T ignoreXmlConfiguration();

135

136

/**

137

* Set a custom MessageInterpolator for constraint message interpolation

138

* @param interpolator MessageInterpolator instance

139

* @return this configuration instance

140

*/

141

T messageInterpolator(MessageInterpolator interpolator);

142

143

/**

144

* Set a custom TraversableResolver for property traversal decisions

145

* @param resolver TraversableResolver instance

146

* @return this configuration instance

147

*/

148

T traversableResolver(TraversableResolver resolver);

149

150

/**

151

* Set a custom ConstraintValidatorFactory for validator instantiation

152

* @param constraintValidatorFactory ConstraintValidatorFactory instance

153

* @return this configuration instance

154

*/

155

T constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory);

156

157

/**

158

* Set a custom ParameterNameProvider for method parameter names

159

* @param parameterNameProvider ParameterNameProvider instance

160

* @return this configuration instance

161

*/

162

T parameterNameProvider(ParameterNameProvider parameterNameProvider);

163

164

/**

165

* Set a custom ClockProvider for time-based validations

166

* @param clockProvider ClockProvider instance

167

* @return this configuration instance

168

*/

169

T clockProvider(ClockProvider clockProvider);

170

171

/**

172

* Add a ValueExtractor for container element validation

173

* @param extractor ValueExtractor instance

174

* @return this configuration instance

175

*/

176

T addValueExtractor(ValueExtractor<?> extractor);

177

178

/**

179

* Add constraint mapping stream for programmatic constraint definition

180

* @param stream InputStream containing constraint mappings

181

* @return this configuration instance

182

*/

183

T addMapping(InputStream stream);

184

185

/**

186

* Add a configuration property

187

* @param name property name

188

* @param value property value

189

* @return this configuration instance

190

*/

191

T addProperty(String name, String value);

192

193

/**

194

* Build the configured ValidatorFactory

195

* @return configured ValidatorFactory instance

196

*/

197

ValidatorFactory buildValidatorFactory();

198

}

199

```

200

201

### Bootstrap Interfaces

202

203

Bootstrap interfaces for provider-specific and generic configuration setup.

204

205

```java { .api }

206

/**

207

* Generic bootstrap for provider-agnostic configuration

208

*/

209

interface GenericBootstrap {

210

/**

211

* Set a custom ValidationProviderResolver

212

* @param resolver ValidationProviderResolver instance

213

* @return this bootstrap instance

214

*/

215

GenericBootstrap providerResolver(ValidationProviderResolver resolver);

216

217

/**

218

* Create a generic configuration instance

219

* @return Configuration instance

220

*/

221

Configuration<?> configure();

222

}

223

224

/**

225

* Provider-specific bootstrap for targeted validation provider configuration

226

* @param <T> type of the provider-specific configuration

227

*/

228

interface ProviderSpecificBootstrap<T extends Configuration<T>> {

229

/**

230

* Set a custom ValidationProviderResolver

231

* @param resolver ValidationProviderResolver instance

232

* @return this bootstrap instance

233

*/

234

ProviderSpecificBootstrap<T> providerResolver(ValidationProviderResolver resolver);

235

236

/**

237

* Create a provider-specific configuration instance

238

* @return provider-specific Configuration instance

239

*/

240

T configure();

241

}

242

```

243

244

### Validator Context

245

246

Context interface for creating customized Validator instances with specific configurations.

247

248

```java { .api }

249

/**

250

* Context for creating customized Validator instances

251

*/

252

interface ValidatorContext {

253

/**

254

* Set a custom MessageInterpolator for this validator

255

* @param messageInterpolator MessageInterpolator instance

256

* @return this context instance

257

*/

258

ValidatorContext messageInterpolator(MessageInterpolator messageInterpolator);

259

260

/**

261

* Set a custom TraversableResolver for this validator

262

* @param traversableResolver TraversableResolver instance

263

* @return this context instance

264

*/

265

ValidatorContext traversableResolver(TraversableResolver traversableResolver);

266

267

/**

268

* Set a custom ConstraintValidatorFactory for this validator

269

* @param factory ConstraintValidatorFactory instance

270

* @return this context instance

271

*/

272

ValidatorContext constraintValidatorFactory(ConstraintValidatorFactory factory);

273

274

/**

275

* Set a custom ParameterNameProvider for this validator

276

* @param parameterNameProvider ParameterNameProvider instance

277

* @return this context instance

278

*/

279

ValidatorContext parameterNameProvider(ParameterNameProvider parameterNameProvider);

280

281

/**

282

* Set a custom ClockProvider for this validator

283

* @param clockProvider ClockProvider instance

284

* @return this context instance

285

*/

286

ValidatorContext clockProvider(ClockProvider clockProvider);

287

288

/**

289

* Get the configured Validator instance

290

* @return customized Validator instance

291

*/

292

Validator getValidator();

293

}

294

```

295

296

### Bootstrap Configuration

297

298

Interface representing configuration loaded from META-INF/validation.xml.

299

300

```java { .api }

301

/**

302

* Configuration information from META-INF/validation.xml

303

*/

304

interface BootstrapConfiguration {

305

/**

306

* Get the default validation provider class name

307

* @return provider class name or null if not specified

308

*/

309

String getDefaultProviderClassName();

310

311

/**

312

* Get constraint validator factory class name

313

* @return factory class name or null if not specified

314

*/

315

String getConstraintValidatorFactoryClassName();

316

317

/**

318

* Get message interpolator class name

319

* @return interpolator class name or null if not specified

320

*/

321

String getMessageInterpolatorClassName();

322

323

/**

324

* Get traversable resolver class name

325

* @return resolver class name or null if not specified

326

*/

327

String getTraversableResolverClassName();

328

329

/**

330

* Get parameter name provider class name

331

* @return provider class name or null if not specified

332

*/

333

String getParameterNameProviderClassName();

334

335

/**

336

* Get clock provider class name

337

* @return provider class name or null if not specified

338

*/

339

String getClockProviderClassName();

340

341

/**

342

* Get value extractor class names

343

* @return set of extractor class names

344

*/

345

Set<String> getValueExtractorClassNames();

346

347

/**

348

* Get constraint mapping resource paths

349

* @return set of resource paths

350

*/

351

Set<String> getConstraintMappingResourcePaths();

352

353

/**

354

* Get configuration properties

355

* @return map of property names to values

356

*/

357

Map<String, String> getProperties();

358

359

/**

360

* Get executable validation configuration

361

* @return ExecutableValidation configuration

362

*/

363

ExecutableValidation getExecutableValidation();

364

365

/**

366

* Check if executable validation is enabled by default

367

* @return true if enabled by default

368

*/

369

boolean isExecutableValidationEnabled();

370

}

371

```

372

373

**Usage Examples:**

374

375

```java

376

import jakarta.validation.*;

377

378

// Custom configuration example

379

Configuration<?> config = Validation.byDefaultProvider()

380

.configure()

381

.messageInterpolator(new CustomMessageInterpolator())

382

.constraintValidatorFactory(new CustomValidatorFactory())

383

.addProperty("hibernate.validator.fail_fast", "true");

384

385

ValidatorFactory factory = config.buildValidatorFactory();

386

Validator validator = factory.getValidator();

387

388

// Validator context customization

389

Validator customValidator = factory.usingContext()

390

.messageInterpolator(new SpecialMessageInterpolator())

391

.getValidator();

392

```