Skip to content

ConfigurationProperties with constructor binding cannot be mocked #18652

Closed
@sdeleuze

Description

@sdeleuze

I have migrated https://spring.io/guides/tutorials/spring-boot-kotlin/ to Spring Boot 2.2.0.RELEASE and updated it to leverage immutable configuration properties. As discussed with @snicoll, @ConfigurationProperties are not scanned by default in test slices, so I have to add to my @WebMvcTest test either @EnableConfigurationProperties(BlogProperties::class) or mock BlogProperties bean.

My test works with @EnableConfigurationProperties(BlogProperties::class) but fails if I try to mockk BlogProperties bean (in my case with @MockkBean from https://github.com/Ninja-Squad/springmockk) with following error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.example.blog.BlogProperties#0': @EnableConfigurationProperties or @ConfigurationPropertiesScan must be used to add @ConstructorBinding type com.example.blog.BlogProperties

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions