没有配置支持的RepositoryOperations用于仓库。请检查您的配置并重试。

huangapple go评论82阅读模式
英文:

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&lt;Product, Long&gt; {
}

Getting the value from repository

private final GenericRepository repository;

    public ProductListener(GenericRepository repository) {
        this.repository = repository;
    }
    var item = this.repository.findAll();

Dependency

implementation(&quot;io.micronaut.data:micronaut-data-hibernate-jpa&quot;)
    implementation(&quot;io.micronaut.mongodb:micronaut-mongo-reactive&quot;)

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。

例如在这里查看:

https://github.com/ilopmar/micronaut-mongo-reactive-sample/blob/master/src/main/java/mongoreactive/MongoController.java

或者在这里:

http://mongodb.github.io/mongo-java-driver-reactivestreams/1.9/javadoc/com/mongodb/reactivestreams/client/MongoClient.html

我猜repositories不支持mongodb。这就是为什么你会得到异常,因为没有真正的数据库可以与repository一起使用。

英文:

Try using the MongoClient not a repository.

See for example here:

https://github.com/ilopmar/micronaut-mongo-reactive-sample/blob/master/src/main/java/mongoreactive/MongoController.java

Or here:

http://mongodb.github.io/mongo-java-driver-reactivestreams/1.9/javadoc/com/mongodb/reactivestreams/client/MongoClient.html

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.

huangapple
  • 本文由 发表于 2020年10月17日 12:29:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/64399009.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定