Skip to content

Scoped Proxy does not consider "defaultCandidate" #35626

@hosea

Description

@hosea

I defined three Services in my configuration:

@Bean(value = "legacyContentService", defaultCandidate = false)
@Scope(value = BeanDefinition.SCOPE_SINGLETON, proxyMode = ScopedProxyMode.INTERFACES)
public ContentService legacyContentService() {
 ....
}

@Bean(value = "contentService", defaultCandidate = false)
@Scope(value = BeanDefinition.SCOPE_SINGLETON, proxyMode = ScopedProxyMode.INTERFACES)
public ContentService contentService() {
  ....		
}

@Bean(value = "contentServiceDispatcher")
@Scope(value = BeanDefinition.SCOPE_SINGLETON, proxyMode = ScopedProxyMode.INTERFACES)
public ContentService contentServiceDispatcher(@Qualifier("legacyContentService") final ContentService legacyContentService, @Qualifier("contentService") ContentService contentService)  {
   return new ContentServiceDispatcher(legacyContentService, contentService);
}

But this lead to an unexpected exception: "no qualifiing bean of type ...ContentSerivce", "expected single matching bean but found 3". So "defaultCandidate = false" does not apply.
Then I removed "proxyMode = ScopeProxyMode.INTERFACES" from the @Scope-Annotations and then it worked. So I took a look at the Creation of the BeanDefinition of scoped beans.

I found, that ScopedProxyUtils#createScopedProxy does not consider the property "defaultCandidate". This property should also be applied to the scoped proxy bean definition.

Found in Spring-aop 6.2.x

I added a PR as proposal: #35627

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: supersededAn issue that has been superseded by anothertype: bugA general bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions