Skip to content

Commit fed1a42

Browse files
committed
Improve BeanDefinitionBuilder to handle the synthetic flag
Closes gh-27141
1 parent cf78895 commit fed1a42

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/support/BeanDefinitionBuilder.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -331,6 +331,15 @@ public BeanDefinitionBuilder setRole(int role) {
331331
return this;
332332
}
333333

334+
/**
335+
* Set whether this bean is 'synthetic', that is, not defined by
336+
* the application itself.
337+
*/
338+
public BeanDefinitionBuilder setSynthetic(boolean synthetic) {
339+
this.beanDefinition.setSynthetic(synthetic);
340+
return this;
341+
}
342+
334343
/**
335344
* Apply the given customizers to the underlying bean definition.
336345
* @since 5.0

spring-beans/src/test/java/org/springframework/beans/factory/support/BeanDefinitionBuilderTests.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ void builderWithRole() {
110110
.isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
111111
}
112112

113+
@Test
114+
void builderWithSynthetic() {
115+
assertThat(BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)
116+
.setSynthetic(true).getBeanDefinition().isSynthetic()).isTrue();
117+
}
118+
113119
@Test
114120
void builderWithCustomizers() {
115121
BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)

0 commit comments

Comments
 (0)