profile
viewpoint

Ask questionsConfigurationProperties with constructor binding cannot be mocked

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
spring-projects/spring-boot

Answer questions philwebb

:(

useful!

Related questions

Dependency resolution fails with Gradle 5.3.x to 5.6.x
[spring-boot 2.3.0] ResponseStatusException reason is ignored - spring-boot hot 3
get error messag Could not fetch the SequenceInformation from the database, hibernate_sequence doesn't exist hot 2
Controller annotated with @Timed and active TimedAspect clashes with WebMvcMetricsFilter hot 2
Source file must be provided failure when running spring-boot:repackage from the command-line hot 2
Actuator: NPE in LongTaskTimingHandlerInterceptor hot 2
NoClassDefFoundError: net/bytebuddy/NamingStrategy$SuffixingRandom$BaseNameResolver hot 2
No bean named 'entityManagerFactory' available hot 2
Bug in org.springframework.boot on 2.2.3.RELEASE version hot 2
"factory already defined" error with spring-boot-maven-plugin in maven multi-module application hot 2
Deadlock between BackgroundPreinitializer and main thread in Spring Cloud Config Server hot 2
spring boot Servlet.service() for servlet [dispatcherServlet] in context with path threw exception hot 2
Migrating OAuth2 from Spring Boot 1.5 to 2.0 Broken hot 2
Add AutoConfiguration support for spring-security-saml2-service-provider hot 2
Validation api missing in 2.3.0.RELEASE hot 2
Github User Rank List