user13617159
user13617159

Reputation:

Consider defining a bean of type 'org.springframework.data.mongodb.core.MongoTemplate' in your configuration

I wanted to ask why does this code throw error with 2.3.0.RELEASE and not with 2.0.6.RELEASE of Spring Data MongoDB:

@Service
public class ServiceX {
    @Autowired private MongoTemplate mongoTemplate;
    @Scheduled(fixedDelay = 1000) public void scheduled() {
        // I am using mongoTemplate here
    }
}

Upvotes: 2

Views: 2610

Answers (1)

Aniket Sahrawat
Aniket Sahrawat

Reputation: 12937

MongoTemplate is an imperative variant. You should use ReactiveMongoTemplate instead since you are on Reactive MongoDB. It used to work in older versions but it won't work with Spring Boot 2.3.0.RELASE and above.

Infact, I created this issue yesterday:

You can always switch to non reactive variant of Spring Data MongoDB using spring-boot-starter-data-mongodb instead of spring-boot-starter-data-mongodb-reactive.

Upvotes: 4

Related Questions