英文:
No backing RepositoryOperations configured for repository. Check your configuration and try again
问题
尝试在使用Micronaut数据与MongoDB时使用RxJavaCrudRepository
。
@Repository
public interface GenericRepository extends RxJavaCrudRepository<Product, Long> {
}
从Repository中获取值:
private final GenericRepository repository;
public ProductListener(GenericRepository repository) {
this.repository = repository;
}
var item = this.repository.findAll();
依赖项:
implementation("io.micronaut.data:micronaut-data-hibernate-jpa")
implementation("io.micronaut.mongodb:micronaut-mongo-reactive")
异常信息:
io.micronaut.context.exceptions.ConfigurationException: No backing
RepositoryOperations configured for repository. Check your
configuration and try again
io.micronaut.context.exceptions.NoSuchBeanException: No bean of type
[io.micronaut.data.operations.PrimaryRepositoryOperations] exists.
Make sure the bean is not disabled by bean requirements (enable trace
logging for 'io.micronaut.context.condition' to check) and if the bean
is enabled then ensure the class is declared a bean and annotation
processing is enabled (for Java and Kotlin the 'micronaut-inject-java'
dependency should be configured as an annotation processor).
英文:
Trying to use RxJavaCrudRepository
with Micronaut data with mongo db.
@Repository
public interface GenericRepository extends RxJavaCrudRepository<Product, Long> {
}
Getting the value from repository
private final GenericRepository repository;
public ProductListener(GenericRepository repository) {
this.repository = repository;
}
var item = this.repository.findAll();
Dependency
implementation("io.micronaut.data:micronaut-data-hibernate-jpa")
implementation("io.micronaut.mongodb:micronaut-mongo-reactive")
Exception
> io.micronaut.context.exceptions.ConfigurationException: No backing
> RepositoryOperations configured for repository. Check your
> configuration and try again
>
>
> io.micronaut.context.exceptions.NoSuchBeanException: No bean of type
> [io.micronaut.data.operations.PrimaryRepositoryOperations] exists.
> Make sure the bean is not disabled by bean requirements (enable trace
> logging for 'io.micronaut.context.condition' to check) and if the bean
> is enabled then ensure the class is declared a bean and annotation
> processing is enabled (for Java and Kotlin the 'micronaut-inject-java'
> dependency should be configured as an annotation processor).
答案1
得分: 1
尝试使用MongoClient,而不是repository。
例如在这里查看:
或者在这里:
我猜repositories不支持mongodb。这就是为什么你会得到异常,因为没有真正的数据库可以与repository一起使用。
英文:
Try using the MongoClient not a repository.
See for example here:
Or here:
I guess repositories are not supporting mongodb. Thats why you get the exception, cause no real database is there to be used with the repo.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论