You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have some places in our auto-configuration where we define a bean using a concrete type where it's typically injected as an interface. The definition that prompted this issue is the following:
A ReactiveMongoOperations bean won't cause the reactiveMongoTemplate bean to back off when it probably should. We're inconsistent about this as another bean in the same class will back off in the presence of a bean defined using the interface:
While beans should generally be defined using their concrete type so that the bean factory has as much type information as possible, mocking a bean using an interface that it implements is a use case for defining a bean using an interface. With the current arrangement, a test that mocks MongoOperations and attempts to autowire that mock will fail:
The failure occurs because there are two MongoOperations beans: mockedMongoOperations from the test configuration and mongoTemplate from Boot's auto-configuration.
The text was updated successfully, but these errors were encountered:
wilkinsona
changed the title
Review use of @ConditionalOnMissingBean to allow a bean defined as an interface to cause a concrete implementation to back off
Some usage of @ConditionalOnMissingBean does not allow a bean defined as an interface to cause a concrete implementation to back off
Sep 6, 2019
See DATAMONGO-2355 and this question on Stack Overflow for some background.
We have some places in our auto-configuration where we define a bean using a concrete type where it's typically injected as an interface. The definition that prompted this issue is the following:
spring-boot/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.java
Lines 74 to 79 in 54126f6
A
ReactiveMongoOperations
bean won't cause thereactiveMongoTemplate
bean to back off when it probably should. We're inconsistent about this as another bean in the same class will back off in the presence of a bean defined using the interface:spring-boot/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/data/mongo/MongoReactiveDataAutoConfiguration.java
Lines 81 to 88 in 54126f6
While beans should generally be defined using their concrete type so that the bean factory has as much type information as possible, mocking a bean using an interface that it implements is a use case for defining a bean using an interface. With the current arrangement, a test that mocks
MongoOperations
and attempts to autowire that mock will fail:The failure occurs because there are two
MongoOperations
beans:mockedMongoOperations
from the test configuration andmongoTemplate
from Boot's auto-configuration.The text was updated successfully, but these errors were encountered: