Axon - DefaultMongoTemplate 类型已弃用

Axon - The type DefaultMongoTemplate is deprecated

我正在开发来自 link 的 Spring Boot + AXON 示例:https://blog.novatec-gmbh.de/event-sourcing-spring-boot-axon/ 并且刚刚更新了 Spring 引导版本 2.1.0.RELEASE

Multiple markers at this line - The type DefaultMongoTemplate is deprecated - The constructor DefaultMongoTemplate(MongoClient) is deprecated

代码

import com.mongodb.MongoClient;
import org.axonframework.eventsourcing.eventstore.EventStorageEngine;
import org.axonframework.mongo.eventsourcing.eventstore.DefaultMongoTemplate;
import org.axonframework.mongo.eventsourcing.eventstore.MongoEventStorageEngine;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class AggregateConfig {
    @Bean
    public EventStorageEngine eventStore(MongoClient client) {
        return new MongoEventStorageEngine(new DefaultMongoTemplate(client));
    }

}

DefaultMongoTemplate 代码似乎已弃用,有什么替代品?

从 Axon 4.0 版开始,扩展包(如 Mongo)已移至专用存储库(您可以在其中找到 here)。此外,当从 Axon 3.x 升级到 4.0 时,我们在基础设施组件上替换了几个构造函数以支持构建器模式。 DefaultMongoTemplate.

是其中一个经历了这种变化的

虽然是那个故事的一部分,但我刚刚查看了 Axon 3.x(因为我假设您目前没有在看 4.0),org.axonframework.mongo.eventhandling.saga.repository.DefaultMongoTemplate 已被弃用,有利于org.axonframework.mongo.DefaultMongoTemplate。我现在从 javadoc 中提取了这个,所以我希望你能看到它。

无论如何,我希望这对你有所帮助! 如果你有变化,我建议升级到 Axon 4.x,因为新功能将添加到该版本而不是版本 3.x。