问题描述
所以首先我添加了一个属性文件:
So at first I added a properties file with:
可以,但是我被迫使用axonframework作为数据库名称,因为它是在我的mongo数据库中创建的.
which works but I was forced to use axonframework as db name because it is what was created in my mongo db.
在这种情况下,现在无法控制数据库名称和其他详细信息,因此我四处检查并发现以下内容:
Now controlling the db name and other details isn't an option in this case, so I went and checked around and found the following:
@configuration
public class AxonConfiguration {
@Value("${mongo.host:127.0.0.1}")
private String mongoHost;
@Value("${mongo.port:27017}")
private int mongoPort;
@Value("${mongo.db:test}")
private String mongoDB;
@Bean
public MongoSagaStore sagaStore() {
return new MongoSagaStore(axonMongoTemplate());
}
@Bean
public TokenStore tokenStore(Serializer serializer) {
return new MongoTokenStore(axonMongoTemplate(), serializer);
}
@Bean
public EventStorageEngine eventStorageEngine(Serializer serializer) {
return new MongoEventStorageEngine(serializer, null, axonMongoTemplate(), new DocumentPerEventStorageStrategy());
}
@Bean
public MongoTemplate axonMongoTemplate() {
return new DefaultMongoTemplate(mongo(), mongoDB);
}
@Bean
public MongoClient mongo() {
MongoFactory mongoFactory = new MongoFactory();
mongoFactory.setMongoAddresses(Collections.singletonList(new ServerAddress(mongoHost, mongoPort)));
return mongoFactory.createMongo();
}
}
现在这显然对人们有用,但是我无法正确使用的是我应该如何设置用户名和密码?
Now apparently this worked for people but what I'm not being able to get right is how am I supposed to set the username and password?
我正在使用axon 4.1,axonframework.extensions.mongo 4.1
I'm using axon 4.1, axonframework.extensions.mongo 4.1
推荐答案
您共享的代码段与Axon Framework 4.x版或Axon Mongo Extension 4.x版不对应.从版本3到版本4的转变已经取代了基础结构组件的几乎所有构造函数,而采用了Builder模式.
The snippet of code you share does not correspond with Axon Framework release 4.x or Axon Mongo Extension release 4.x. The shift from version 3 to 4 has replaced almost all constructors of the infrastructure components in favor of the Builder pattern.
因此,您不应该执行new MongoEventStorageEngine(...)
,而应该执行以下操作:
As such, you should not be able to do new MongoEventStorageEngine(...)
, but instead should do:
MongoEventStorageEngine.builder().mongoTemplate(axonMongoTemplate).build()
如果您仍然能够使用构造函数,那么我认为您在类路径上的某个地方仍然还有Axon 3!
If you're still able to use the constructor, I assume you still have Axon 3 somewhere on the class path!
关于Mongo的细节,顺便说一句,我相信@PolishCivil的声明.
Regarding the Mongo specifics, I'd trust @PolishCivil's statement by the way.
希望这会有所帮助!
这篇关于在春季启动时为Axon Framework设置Mongo Extension的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!