Improve BeanDefinitionBuilder to handle the synthetic flag

Closes gh-27141
This commit is contained in:
Stephane Nicoll 2021-07-07 16:13:19 +02:00
parent cf78895ba0
commit fed1a426b6
2 changed files with 16 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -331,6 +331,15 @@ public final class BeanDefinitionBuilder {
return this;
}
/**
* Set whether this bean is 'synthetic', that is, not defined by
* the application itself.
*/
public BeanDefinitionBuilder setSynthetic(boolean synthetic) {
this.beanDefinition.setSynthetic(synthetic);
return this;
}
/**
* Apply the given customizers to the underlying bean definition.
* @since 5.0

View File

@ -110,6 +110,12 @@ class BeanDefinitionBuilderTests {
.isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
}
@Test
void builderWithSynthetic() {
assertThat(BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)
.setSynthetic(true).getBeanDefinition().isSynthetic()).isTrue();
}
@Test
void builderWithCustomizers() {
BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)