Skip to content

spring-context-indexer doesn't support Java records #26909

Closed
@sergey-morenets

Description

@sergey-morenets

Spring version: 5.3.6
JDK: 16.0.1

It seems that spring-context-indexer library doesn't support Java records. If I declare a record as Spring bean:

@Component
public record ServiceManager() {}

then META-INF/spring.components doesn't contain entry for this type. And Spring fails to load it during startup. I looked into source code and the following blocks seem to responsible for that:

CandidateComponentsIndexer:

private static final Set<ElementKind> TYPE_KINDS =
 Collections.unmodifiableSet(EnumSet.of(ElementKind.CLASS, ElementKind.INTERFACE));

IndexedStereotypesProvider:

	@Override
	public Set<String> getStereotypes(Element element) {
		Set<String> stereotypes = new LinkedHashSet<>();
		ElementKind kind = element.getKind();
		if (kind != ElementKind.CLASS && kind != ElementKind.INTERFACE) {
			return stereotypes;
		}

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions