or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

annotation-config.mdaot-support.mdbean-definition.mdbean-factory.mdindex.mdproperty-access.mdxml-config.md

bean-factory.mddocs/

0

# Bean Factory and Container

1

2

Core IoC container functionality for managing bean definitions, lifecycle, and dependency injection. The bean factory serves as the central registry and factory for application objects, providing sophisticated dependency resolution and lifecycle management capabilities.

3

4

## Capabilities

5

6

### Bean Factory Interface

7

8

The central interface for accessing Spring's IoC container, providing basic bean lookup and metadata query capabilities.

9

10

```java { .api }

11

/**

12

* Root interface for accessing a Spring bean container.

13

* Provides basic functionality for retrieving beans and querying their metadata.

14

*/

15

interface BeanFactory {

16

/** Used to dereference a FactoryBean instance and distinguish it from beans created by the FactoryBean. */

17

String FACTORY_BEAN_PREFIX = "&";

18

19

/** Used to dereference a FactoryBean instance and distinguish it from beans created by the FactoryBean. */

20

char FACTORY_BEAN_PREFIX_CHAR = '&';

21

22

/**

23

* Return an instance, which may be shared or independent, of the specified bean.

24

* @param name the name of the bean to retrieve

25

* @return an instance of the bean

26

* @throws NoSuchBeanDefinitionException if there is no bean with the specified name

27

* @throws BeansException if the bean could not be obtained

28

*/

29

Object getBean(String name) throws BeansException;

30

31

/**

32

* Return an instance, which may be shared or independent, of the specified bean.

33

* @param name the name of the bean to retrieve

34

* @param requiredType type the bean must match; can be an interface or superclass

35

* @return an instance of the bean

36

* @throws NoSuchBeanDefinitionException if there is no such bean definition

37

* @throws BeanNotOfRequiredTypeException if the bean is not of the required type

38

* @throws BeansException if the bean could not be created

39

*/

40

<T> T getBean(String name, Class<T> requiredType) throws BeansException;

41

42

/**

43

* Return the bean instance that uniquely matches the given object type, if any.

44

* @param requiredType type the bean must match; can be an interface or superclass

45

* @return an instance of the single bean matching the required type

46

* @throws NoSuchBeanDefinitionException if no bean of the given type was found

47

* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found

48

* @throws BeansException if the bean could not be created

49

*/

50

<T> T getBean(Class<T> requiredType) throws BeansException;

51

52

/**

53

* Return an instance, which may be shared or independent, of the specified bean.

54

* @param name the name of the bean to retrieve

55

* @param args arguments to use when creating a bean instance using explicit arguments

56

* @return an instance of the bean

57

* @throws NoSuchBeanDefinitionException if there is no such bean definition

58

* @throws BeanDefinitionStoreException if arguments have been given but the affected bean isn't a prototype

59

* @throws BeansException if the bean could not be created

60

*/

61

Object getBean(String name, Object... args) throws BeansException;

62

63

/**

64

* Return an instance, which may be shared or independent, of the specified bean.

65

* @param requiredType type the bean must match; can be an interface or superclass

66

* @param args arguments to use when creating a bean instance using explicit arguments

67

* @return an instance of the bean

68

* @throws NoSuchBeanDefinitionException if no bean of the given type was found

69

* @throws NoUniqueBeanDefinitionException if more than one bean of the given type was found

70

* @throws BeansException if the bean could not be created

71

*/

72

<T> T getBean(Class<T> requiredType, Object... args) throws BeansException;

73

74

/**

75

* Does this bean factory contain a bean definition or externally registered singleton instance with the given name?

76

* @param name the name of the bean to query

77

* @return whether this bean factory contains a bean with the given name

78

*/

79

boolean containsBean(String name);

80

81

/**

82

* Is this bean a shared singleton?

83

* @param name the name of the bean to query

84

* @return whether this bean corresponds to a singleton instance

85

* @throws NoSuchBeanDefinitionException if there is no bean with the given name

86

*/

87

boolean isSingleton(String name) throws NoSuchBeanDefinitionException;

88

89

/**

90

* Is this bean a prototype (not a singleton)?

91

* @param name the name of the bean to query

92

* @return whether this bean will always create independent instances

93

* @throws NoSuchBeanDefinitionException if there is no bean with the given name

94

*/

95

boolean isPrototype(String name) throws NoSuchBeanDefinitionException;

96

97

/**

98

* Check whether the bean with the given name matches the specified type.

99

* @param name the name of the bean to query

100

* @param typeToMatch the type to match against (as a ResolvableType)

101

* @return true if the bean type matches, false if it doesn't or cannot be determined yet

102

* @throws NoSuchBeanDefinitionException if there is no bean with the given name

103

*/

104

boolean isTypeMatch(String name, ResolvableType typeToMatch) throws NoSuchBeanDefinitionException;

105

106

/**

107

* Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options.

108

* @param requiredType type the bean must match; can be an interface or superclass

109

* @return a corresponding provider handle

110

*/

111

<T> ObjectProvider<T> getBeanProvider(Class<T> requiredType);

112

113

/**

114

* Return a provider for the specified bean, allowing for lazy on-demand retrieval of instances, including availability and uniqueness options.

115

* @param requiredType type the bean must match; can be a generic type declaration

116

* @return a corresponding provider handle

117

*/

118

<T> ObjectProvider<T> getBeanProvider(ResolvableType requiredType);

119

120

/**

121

* Check whether the bean with the given name matches the specified type.

122

* @param name the name of the bean to query

123

* @param typeToMatch the type to match against (as a Class)

124

* @return true if the bean type matches, false if it doesn't or cannot be determined yet

125

* @throws NoSuchBeanDefinitionException if there is no bean with the given name

126

*/

127

boolean isTypeMatch(String name, Class<?> typeToMatch) throws NoSuchBeanDefinitionException;

128

129

/**

130

* Determine the type of the bean with the given name.

131

* @param name the name of the bean to query

132

* @return the type of the bean, or null if not determinable

133

* @throws NoSuchBeanDefinitionException if there is no bean with the given name

134

*/

135

Class<?> getType(String name) throws NoSuchBeanDefinitionException;

136

137

/**

138

* Determine the type of the bean with the given name.

139

* @param name the name of the bean to query

140

* @param allowFactoryBeanInit whether a FactoryBean type match is allowed to trigger initialization of the FactoryBean

141

* @return the type of the bean, or null if not determinable

142

* @throws NoSuchBeanDefinitionException if there is no bean with the given name

143

*/

144

Class<?> getType(String name, boolean allowFactoryBeanInit) throws NoSuchBeanDefinitionException;

145

146

/**

147

* Return the aliases for the given bean name, if any.

148

* @param name the bean name to check for aliases

149

* @return the aliases, or an empty array if none

150

*/

151

String[] getAliases(String name);

152

}

153

```

154

155

### Autowire Capable Bean Factory

156

157

Extended bean factory interface that exposes bean creation, configuration, and autowiring capabilities.

158

159

```java { .api }

160

/**

161

* Extension of the BeanFactory interface to be implemented by bean factories that are capable of autowiring.

162

*/

163

interface AutowireCapableBeanFactory extends BeanFactory {

164

/** Constant that indicates no externally defined autowiring. */

165

int AUTOWIRE_NO = 0;

166

/** Constant that indicates autowiring bean properties by name. */

167

int AUTOWIRE_BY_NAME = 1;

168

/** Constant that indicates autowiring bean properties by type. */

169

int AUTOWIRE_BY_TYPE = 2;

170

/** Constant that indicates autowiring the greediest constructor. */

171

int AUTOWIRE_CONSTRUCTOR = 3;

172

/** Constant that indicates determining an appropriate autowire strategy through introspection of the bean class (deprecated). */

173

int AUTOWIRE_AUTODETECT = 4;

174

175

/** Suffix for generated bean names for original instances when a bean is enhanced with CGLIB. */

176

String ORIGINAL_INSTANCE_SUFFIX = ".ORIGINAL";

177

178

/**

179

* Fully create a new bean instance of the given class.

180

* @param beanClass the class of the bean to create

181

* @return the new bean instance

182

* @throws BeansException if instantiation or wiring failed

183

*/

184

<T> T createBean(Class<T> beanClass) throws BeansException;

185

186

/**

187

* Populate the given bean instance through applying after-instantiation callbacks and bean property post-processing.

188

* @param existingBean the existing bean instance

189

* @throws BeansException if wiring failed

190

*/

191

void autowireBean(Object existingBean) throws BeansException;

192

193

/**

194

* Configure the given raw bean: autowiring bean properties, applying bean property values, applying factory callbacks.

195

* @param existingBean the existing bean instance

196

* @param beanName the name of the bean, to be passed to it if necessary

197

* @return the bean instance to use, either the original or a wrapped one

198

* @throws BeansException if the initialization failed

199

*/

200

Object configureBean(Object existingBean, String beanName) throws BeansException;

201

202

/**

203

* Resolve the bean instance that uniquely matches the given object type, if any, including its bean name.

204

* @param requiredType type the bean must match; can be an interface or superclass

205

* @return the bean name plus bean instance

206

* @throws NoSuchBeanDefinitionException if no matching bean was found

207

* @throws NoUniqueBeanDefinitionException if more than one matching bean was found

208

* @throws BeansException if the bean could not be created

209

*/

210

<T> NamedBeanHolder<T> resolveNamedBean(Class<T> requiredType) throws BeansException;

211

212

/**

213

* Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessBeforeInitialization methods.

214

* @param existingBean the existing bean instance

215

* @param beanName the name of the bean, to be passed to it if necessary

216

* @return the bean instance to use, either the original or a wrapped one

217

* @throws BeansException if any post-processing failed

218

*/

219

Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName) throws BeansException;

220

221

/**

222

* Initialize the given raw bean, applying factory callbacks such as setBeanName and setBeanFactory, also applying all bean post-processors (including ones which might wrap the given raw bean).

223

* @param existingBean the existing bean instance

224

* @param beanName the name of the bean, to be passed to it if necessary

225

* @return the bean instance to use, either the original or a wrapped one

226

* @throws BeansException if the initialization failed

227

*/

228

Object initializeBean(Object existingBean, String beanName) throws BeansException;

229

230

/**

231

* Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessBeforeInitialization methods.

232

* @param existingBean the existing bean instance

233

* @param beanName the name of the bean, to be passed to it if necessary

234

* @return the bean instance to use, either the original or a wrapped one

235

* @throws BeansException if any post-processing failed

236

* @deprecated as of 6.1, in favor of initializeBean

237

*/

238

Object applyBeanPostProcessorsBeforeInitialization(Object existingBean, String beanName) throws BeansException;

239

240

/**

241

* Apply BeanPostProcessors to the given existing bean instance, invoking their postProcessAfterInitialization methods.

242

* @param existingBean the existing bean instance

243

* @param beanName the name of the bean, to be passed to it if necessary

244

* @return the bean instance to use, either the original or a wrapped one

245

* @throws BeansException if any post-processing failed

246

* @deprecated as of 6.1, in favor of initializeBean

247

*/

248

Object applyBeanPostProcessorsAfterInitialization(Object existingBean, String beanName) throws BeansException;

249

250

/**

251

* Destroy the given bean instance (usually a prototype instance obtained from this factory) according to its bean definition.

252

* @param existingBean the bean instance to destroy

253

*/

254

void destroyBean(Object existingBean);

255

256

/**

257

* Resolve the bean instance that uniquely matches the given object type, if any, including its bean name.

258

* @param requiredType type the bean must match; can be an interface or superclass

259

* @return the bean name plus bean instance

260

* @throws NoSuchBeanDefinitionException if no matching bean was found

261

* @throws NoUniqueBeanDefinitionException if more than one matching bean was found

262

* @throws BeansException if the bean could not be created

263

*/

264

<T> NamedBeanHolder<T> resolveNamedBean(Class<T> requiredType) throws BeansException;

265

266

/**

267

* Resolve a bean instance for the given bean name, providing a dependency descriptor for exposure to target factory methods.

268

* @param name the name of the bean to look up

269

* @param descriptor the dependency descriptor for the requesting injection point

270

* @return the corresponding bean instance

271

* @throws NoSuchBeanDefinitionException if there is no bean with the specified name

272

* @throws BeansException if the bean could not be obtained

273

*/

274

Object resolveBeanByName(String name, DependencyDescriptor descriptor) throws BeansException;

275

276

/**

277

* Resolve the specified dependency against the beans defined in this factory.

278

* @param descriptor the descriptor for the dependency (field/method/constructor)

279

* @param requestingBeanName the name of the bean which declares the given dependency

280

* @return the resolved object, or null if not found

281

* @throws NoSuchBeanDefinitionException if no matching bean was found

282

* @throws NoUniqueBeanDefinitionException if more than one matching bean was found

283

* @throws BeansException if dependency resolution failed for any other reason

284

*/

285

Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName) throws BeansException;

286

287

/**

288

* Resolve the specified dependency against the beans defined in this factory.

289

* @param descriptor the descriptor for the dependency (field/method/constructor)

290

* @param requestingBeanName the name of the bean which declares the given dependency

291

* @param autowiredBeanNames a Set that all names of autowired beans (used for resolving the given dependency) are supposed to be added to

292

* @param typeConverter the TypeConverter to use for populating arrays and collections

293

* @return the resolved object, or null if not found

294

* @throws NoSuchBeanDefinitionException if no matching bean was found

295

* @throws NoUniqueBeanDefinitionException if more than one matching bean was found

296

* @throws BeansException if dependency resolution failed for any other reason

297

*/

298

Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName, Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException;

299

}

300

```

301

302

### Listable Bean Factory

303

304

Extension of the BeanFactory interface that allows enumeration of all bean instances, rather than just looking up individual beans by name.

305

306

```java { .api }

307

/**

308

* Extension of the BeanFactory interface to be implemented by bean factories that can enumerate all their bean instances.

309

*/

310

interface ListableBeanFactory extends BeanFactory {

311

/**

312

* Check if this registry contains a bean definition with the given name.

313

* @param beanName the name of the bean to look for

314

* @return if this registry contains a bean definition with the given name

315

*/

316

boolean containsBeanDefinition(String beanName);

317

318

/**

319

* Return the number of beans defined in the registry.

320

* @return the number of beans defined in the registry

321

*/

322

int getBeanDefinitionCount();

323

324

/**

325

* Return the names of all beans defined in this registry.

326

* @return the names of all beans defined in this registry, or an empty array if none defined

327

*/

328

String[] getBeanDefinitionNames();

329

330

/**

331

* Return the names of beans matching the given type (including subclasses).

332

* @param type the class or interface to match, or null for all bean names

333

* @return the names of beans (or objects created by FactoryBeans) matching the given object type

334

*/

335

String[] getBeanNamesForType(ResolvableType type);

336

337

/**

338

* Return the names of beans matching the given type (including subclasses).

339

* @param type the class or interface to match, or null for all bean names

340

* @return the names of beans (or objects created by FactoryBeans) matching the given object type

341

*/

342

String[] getBeanNamesForType(Class<?> type);

343

344

/**

345

* Return the bean instances that match the given object type (including subclasses).

346

* @param type the class or interface to match, or null for all concrete beans

347

* @return a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values

348

* @throws BeansException if a bean could not be created

349

*/

350

<T> Map<String, T> getBeansOfType(Class<T> type) throws BeansException;

351

352

/**

353

* Find all names of beans which are annotated with the supplied Annotation type.

354

* @param annotationType the type of annotation to look for

355

* @return the names of all matching beans

356

*/

357

String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType);

358

359

/**

360

* Find all beans which are annotated with the supplied Annotation type.

361

* @param annotationType the type of annotation to look for

362

* @return a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values

363

* @throws BeansException if a bean could not be created

364

*/

365

Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) throws BeansException;

366

367

/**

368

* Find an Annotation of annotationType on the specified bean.

369

* @param beanName the name of the bean to look for annotations on

370

* @param annotationType the type of annotation to look for

371

* @return the annotation of the given type if found, or null otherwise

372

* @throws NoSuchBeanDefinitionException if there is no bean with the given name

373

*/

374

<A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType) throws NoSuchBeanDefinitionException;

375

}

376

```

377

378

### Default Listable Bean Factory

379

380

The default implementation of ListableBeanFactory and BeanDefinitionRegistry interfaces, providing full bean factory functionality.

381

382

```java { .api }

383

/**

384

* Spring's default implementation of the ConfigurableListableBeanFactory and BeanDefinitionRegistry interfaces.

385

*/

386

class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory

387

implements ConfigurableListableBeanFactory, BeanDefinitionRegistry {

388

389

/**

390

* Create a new DefaultListableBeanFactory.

391

*/

392

public DefaultListableBeanFactory();

393

394

/**

395

* Create a new DefaultListableBeanFactory with the given parent.

396

* @param parentBeanFactory the parent BeanFactory

397

*/

398

public DefaultListableBeanFactory(BeanFactory parentBeanFactory);

399

400

/**

401

* Set whether it should be allowed to override bean definitions by registering a different definition with the same name.

402

* @param allowBeanDefinitionOverriding whether to allow bean definition overriding

403

*/

404

public void setAllowBeanDefinitionOverriding(boolean allowBeanDefinitionOverriding);

405

406

/**

407

* Return whether it's allowed to override bean definitions by registering a different definition with the same name.

408

* @return whether bean definition overriding is allowed

409

*/

410

public boolean isAllowBeanDefinitionOverriding();

411

412

/**

413

* Set whether the factory is allowed to eagerly load bean classes even for bean definitions that are marked as "lazy-init".

414

* @param allowEagerClassLoading whether to allow eager class loading

415

*/

416

public void setAllowEagerClassLoading(boolean allowEagerClassLoading);

417

418

/**

419

* Return whether the factory is allowed to eagerly load bean classes.

420

* @return whether eager class loading is allowed

421

*/

422

public boolean isAllowEagerClassLoading();

423

424

/**

425

* Set the bootstrap executor to use for bootstrapping the bean factory.

426

* @param bootstrapExecutor the bootstrap executor, or null for synchronous bootstrapping

427

*/

428

public void setBootstrapExecutor(Executor bootstrapExecutor);

429

430

/**

431

* Return the bootstrap executor for this bean factory.

432

* @return the bootstrap executor, or null if none set

433

*/

434

public Executor getBootstrapExecutor();

435

}

436

```

437

438

**Usage Examples:**

439

440

```java

441

import org.springframework.beans.factory.BeanFactory;

442

import org.springframework.beans.factory.support.DefaultListableBeanFactory;

443

import org.springframework.beans.factory.support.RootBeanDefinition;

444

445

// Create bean factory

446

DefaultListableBeanFactory factory = new DefaultListableBeanFactory();

447

448

// Register bean definition programmatically

449

RootBeanDefinition beanDef = new RootBeanDefinition(MyService.class);

450

beanDef.setScope("singleton");

451

beanDef.setLazyInit(false);

452

factory.registerBeanDefinition("myService", beanDef);

453

454

// Retrieve bean

455

MyService service = factory.getBean("myService", MyService.class);

456

457

// Check bean metadata

458

boolean isSingleton = factory.isSingleton("myService");

459

boolean containsBean = factory.containsBean("myService");

460

461

// List all beans of a type

462

Map<String, MyService> services = factory.getBeansOfType(MyService.class);

463

```

464

465

### Factory Bean Support

466

467

Support for FactoryBean instances that create objects through custom factory logic.

468

469

```java { .api }

470

/**

471

* Interface to be implemented by objects used within a BeanFactory which are themselves factories for individual objects.

472

*/

473

interface FactoryBean<T> {

474

/**

475

* Return an instance (possibly shared or independent) of the object managed by this factory.

476

* @return an instance of the bean (can be null)

477

* @throws Exception in case of creation errors

478

*/

479

T getObject() throws Exception;

480

481

/**

482

* Return the type of object that this FactoryBean creates.

483

* @return the type of object that this FactoryBean creates, or null if not known at the time of the call

484

*/

485

Class<?> getObjectType();

486

487

/**

488

* Is the object managed by this factory a singleton?

489

* @return whether the exposed object is a singleton

490

*/

491

default boolean isSingleton() {

492

return true;

493

}

494

}

495

496

/**

497

* Extension of FactoryBean which adds support for returning a prototype object.

498

*/

499

interface SmartFactoryBean<T> extends FactoryBean<T> {

500

/**

501

* Is the object managed by this factory a prototype?

502

* @return whether the exposed object is a prototype

503

*/

504

default boolean isPrototype() {

505

return false;

506

}

507

508

/**

509

* Does this FactoryBean expect eager initialization?

510

* @return whether eager initialization applies

511

*/

512

default boolean isEagerInit() {

513

return false;

514

}

515

}

516

```

517

518

### Object Provider

519

520

Variant of ObjectFactory designed specifically for injection points, allowing for programmatic optionality and lenient not-unique handling.

521

522

```java { .api }

523

/**

524

* Variant of ObjectFactory designed specifically for injection points.

525

*/

526

interface ObjectProvider<T> extends ObjectFactory<T>, Iterable<T> {

527

/**

528

* Return an instance (possibly shared or independent) of the object managed by this factory.

529

* @return an object instance from this factory

530

* @throws BeansException in case of creation errors

531

*/

532

T getObject() throws BeansException;

533

534

/**

535

* Return an instance (possibly shared or independent) of the object managed by this factory.

536

* @return an object instance from this factory, or null if not available

537

* @throws BeansException in case of creation errors

538

*/

539

T getIfAvailable() throws BeansException;

540

541

/**

542

* Return an instance (possibly shared or independent) of the object managed by this factory.

543

* @param defaultSupplier a callback for supplying a default object if none present

544

* @return an object instance from this factory if available, otherwise the supplied default

545

* @throws BeansException in case of creation errors

546

*/

547

T getIfAvailable(Supplier<T> defaultSupplier) throws BeansException;

548

549

/**

550

* Consume an instance (possibly shared or independent) of the object managed by this factory, if available.

551

* @param dependencyConsumer a callback for processing the target object if available

552

* @throws BeansException in case of creation errors

553

*/

554

void ifAvailable(Consumer<T> dependencyConsumer) throws BeansException;

555

556

/**

557

* Return an instance (possibly shared or independent) of the object managed by this factory.

558

* @return an object instance from this factory if unique, otherwise throw NoUniqueBeanDefinitionException

559

* @throws BeansException in case of creation errors

560

*/

561

T getIfUnique() throws BeansException;

562

563

/**

564

* Return an instance (possibly shared or independent) of the object managed by this factory.

565

* @param defaultSupplier a callback for supplying a default object if not unique

566

* @return an object instance from this factory if unique, otherwise the supplied default

567

* @throws BeansException in case of creation errors

568

*/

569

T getIfUnique(Supplier<T> defaultSupplier) throws BeansException;

570

571

/**

572

* Consume an instance (possibly shared or independent) of the object managed by this factory, if unique.

573

* @param dependencyConsumer a callback for processing the target object if unique

574

* @throws BeansException in case of creation errors

575

*/

576

void ifUnique(Consumer<T> dependencyConsumer) throws BeansException;

577

578

/**

579

* Return a sequential Stream over all matching object instances, without specific ordering guarantees.

580

* @return a sequential Stream of matching instances

581

*/

582

Stream<T> stream();

583

584

/**

585

* Return a sequential Stream over all matching object instances, pre-ordered according to the factory's common order comparator.

586

* @return a sequential Stream of matching instances, ordered if possible

587

*/

588

Stream<T> orderedStream();

589

}

590

```

591

592

### Configurable Bean Factory

593

594

Extension of BeanFactory that provides configuration facilities for a bean factory on top of the BeanFactory SPI.

595

596

```java { .api }

597

/**

598

* Configuration interface to be implemented by most bean factories.

599

*/

600

interface ConfigurableBeanFactory extends HierarchicalBeanFactory, SingletonBeanRegistry {

601

String SCOPE_SINGLETON = "singleton";

602

String SCOPE_PROTOTYPE = "prototype";

603

604

void setParentBeanFactory(BeanFactory parentBeanFactory) throws IllegalStateException;

605

void setBeanClassLoader(ClassLoader beanClassLoader);

606

ClassLoader getBeanClassLoader();

607

void setTempClassLoader(ClassLoader tempClassLoader);

608

ClassLoader getTempClassLoader();

609

void setCacheBeanMetadata(boolean cacheBeanMetadata);

610

boolean isCacheBeanMetadata();

611

void setBeanExpressionResolver(BeanExpressionResolver resolver);

612

BeanExpressionResolver getBeanExpressionResolver();

613

void setConversionService(ConversionService conversionService);

614

ConversionService getConversionService();

615

void addPropertyEditorRegistrar(PropertyEditorRegistrar registrar);

616

void registerCustomEditor(Class<?> requiredType, Class<? extends PropertyEditor> propertyEditorClass);

617

void copyRegisteredEditorsTo(PropertyEditorRegistry registry);

618

void setTypeConverter(TypeConverter typeConverter);

619

TypeConverter getTypeConverter();

620

void addEmbeddedValueResolver(StringValueResolver valueResolver);

621

boolean hasEmbeddedValueResolver();

622

String resolveEmbeddedValue(String value);

623

void addBeanPostProcessor(BeanPostProcessor beanPostProcessor);

624

int getBeanPostProcessorCount();

625

void registerScope(String scopeName, Scope scope);

626

String[] getRegisteredScopeNames();

627

Scope getRegisteredScope(String scopeName);

628

AccessControlContext getAccessControlContext();

629

void copyConfigurationFrom(ConfigurableBeanFactory otherFactory);

630

void registerAlias(String beanName, String alias) throws BeanDefinitionStoreException;

631

void resolveAliases(StringValueResolver valueResolver);

632

BeanDefinition getMergedBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;

633

boolean isFactoryBean(String name) throws NoSuchBeanDefinitionException;

634

void setCurrentlyInCreation(String beanName, boolean inCreation);

635

boolean isCurrentlyInCreation(String beanName);

636

void registerDependentBean(String beanName, String dependentBeanName);

637

String[] getDependentBeans(String beanName);

638

String[] getDependenciesForBean(String beanName);

639

void destroyBean(String beanName, Object beanInstance);

640

void destroyScopedBean(String beanName);

641

void destroySingletons();

642

}

643

644

/**

645

* Configuration interface to be implemented by most listable bean factories.

646

*/

647

interface ConfigurableListableBeanFactory extends ListableBeanFactory, AutowireCapableBeanFactory, ConfigurableBeanFactory {

648

void ignoreDependencyType(Class<?> type);

649

void ignoreDependencyInterface(Class<?> ifc);

650

void registerResolvableDependency(Class<?> dependencyType, Object autowiredValue);

651

boolean isAutowireCandidate(String beanName, DependencyDescriptor descriptor) throws NoSuchBeanDefinitionException;

652

BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;

653

Iterator<String> getBeanNamesIterator();

654

void clearMetadataCache();

655

void freezeConfiguration();

656

boolean isConfigurationFrozen();

657

void preInstantiateSingletons() throws BeansException;

658

}

659

660

/**

661

* Interface that defines a registry for shared bean instances.

662

*/

663

interface SingletonBeanRegistry {

664

void registerSingleton(String beanName, Object singletonObject);

665

Object getSingleton(String beanName);

666

boolean containsSingleton(String beanName);

667

String[] getSingletonNames();

668

int getSingletonCount();

669

Object getSingletonMutex();

670

}

671

672

/**

673

* Sub-interface implemented by bean factories that can be part of a hierarchy.

674

*/

675

interface HierarchicalBeanFactory extends BeanFactory {

676

BeanFactory getParentBeanFactory();

677

boolean containsLocalBean(String name);

678

}

679

```

680

681

### Bean Factory Post Processing

682

683

Support for modifying bean factories after all bean definitions have been loaded but before bean instantiation.

684

685

```java { .api }

686

/**

687

* Factory hook that allows for custom modification of an application context's bean definitions.

688

*/

689

interface BeanFactoryPostProcessor {

690

void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException;

691

}

692

693

/**

694

* Extension to the standard BeanFactoryPostProcessor SPI.

695

*/

696

interface BeanDefinitionRegistryPostProcessor extends BeanFactoryPostProcessor {

697

void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException;

698

}

699

700

/**

701

* Interface to be implemented by bean post-processors that apply after bean definition merging.

702

*/

703

interface MergedBeanDefinitionPostProcessor extends BeanPostProcessor {

704

void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName);

705

default void resetBeanDefinition(String beanName) {

706

// No-op by default

707

}

708

}

709

```

710