官方tutorial似乎缺少如何连接到MongoDB集群?
以下是我的要求:
我能够弄清楚如何创建我的存储库和查询。但是无法将存储库连接为bean。
org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.my.TestRepository] found
这是我基于Java的配置:
@EnableMongoRepositories
public class RepositoryConfig extends AbstractMongoConfiguration {
@Override
protected String getDatabaseName() {
return "test";
}
@Override
@Bean
public Mongo mongo() throws Exception {
List<MongoCredential> credentials = new LinkedList<>();
MongoCredential credential = MongoCredential.createCredential("test", getDatabaseName(), "test".toCharArray());
credentials.add(credential);
Mongo mongo = new MongoClient(new ServerAddress("localhost", 27017), credentials);
return mongo;
}
}
这就是我在我的存储库中循环的方式:
@Autowired
TestRepository testRepository;
我把Java配置文件(上面)和我的Repository
类放在同一个包中。
我是否需要提供任何其他配置才能自动加载Repository
类?