Skip to content

Commit

Permalink
fix: Improve detection for prototype beans (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewVaadin committed Nov 8, 2023
1 parent 9e56548 commit 4e345d4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
Expand Up @@ -104,7 +104,8 @@ private TransientDescriptor detectBean(Object target, Field field) {

private boolean matchesPrototype(String beanName, Object beanDefinition,
Class<?> fieldValueType) {
return appCtx.isPrototype(beanName)
return appCtx.containsBeanDefinition(beanName)
&& appCtx.isPrototype(beanName)
&& beanDefinition.getClass() == fieldValueType;
}

Expand Down
Expand Up @@ -45,7 +45,6 @@ void processConstructorInjectedComponent(
.readWithTransients();
Assertions.assertThat(result).isNotSameAs(target)
.isExactlyInstanceOf(TestConfig.CtorInjectionTarget.class)
.hasNoNullFieldsOrProperties()
.asInstanceOf(InstanceOfAssertFactories
.type(TestConfig.CtorInjectionTarget.class))
.extracting(obj -> obj.defaultImpl, obj -> obj.alternative)
Expand Down
Expand Up @@ -61,6 +61,7 @@ public void execute() {
static class CtorInjectionTarget implements Serializable {
transient TestService defaultImpl;
transient TestService alternative;
transient Object nonBeanTransient = new Object();

public CtorInjectionTarget(TestService defaultImpl,
@Qualifier("ALTERNATIVE") TestService alternative) {
Expand Down Expand Up @@ -91,6 +92,7 @@ static class PrototypeTarget implements Serializable {
@Autowired
@Qualifier("EXTENSION")
transient PrototypeComponent extPrototypeScoped;
transient Object nonBeanTransient = new Object();
}

interface PrototypeService {
Expand Down Expand Up @@ -119,6 +121,7 @@ static class PrototypeServiceTarget implements Serializable {
@Autowired
@Qualifier("B")
transient PrototypeService prototypeServiceB;
transient Object nonBeanTransient = new Object();
}

@Component
Expand Down

0 comments on commit 4e345d4

Please sign in to comment.