Skip to content

BeanCurrentlyInCreationException with Spring Boot 2.6 and Circular References #2741

@AnWeber

Description

@AnWeber

After upgrading to Spring Boot 2.6.3, a BeanCurrentlyInCreationException may occur. This is triggered when two mappers reference each other and thus form a circle

@Mapper( componentModel = "spring",  uses = { FooMapper.class })
public interface BarMapper {
    Bar toBo(BarDto dto);
    BarDto toDto(Bar obj) ;
}
@Mapper( componentModel = "spring",  uses = { BarMapper.class })
public interface ForMapper {
    Foo toBo(FooDto dto);
    FooDto toDto(Foo obj) ;
}

Circle detection is a change from Spring Boot 2.6 (Release Notes). Currently there is also a possibility to work around the problem by setting spring.main.allow-circular-references=true.

A better way would be to work around the problem using @Lazy Annotation. Is it possible to extend the SpringComponentProcessor to enable @Lazy autowire support?

example.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions