ArangoDB 在简单应用程序中使用Spring Data 获取Arango存储库的不满足依赖项

eaf3rand  于 2022-12-09  发布在  Go
关注(0)|答案(1)|浏览(233)

我正在尝试用Spring Data启动一个简单的Arango应用程序。我的Arango DB正在本地主机和默认端口上的Docker中运行。
该项目使用Intellij构建为启用Sping Boot Groovy的项目。
我已经把演示应用程序推到了github here,它是最简单的。
我这样做是为了遵循在线文档,但在结构上我将模型类放在模型文件夹中,将存储库接口放在存储库文件夹中。
当我尝试运行这个程序时,我得到了这个错误。但就我所知,我已经完成了预期的从AbstractRepository<Organisation.class>扩展的工作。它说ArangoOperations类型的参数依赖关系不明确,但我没有直接在仓库中这样做。
我做错了什么?

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'organisationRepository': Unsatisfied dependency expressed through constructor parameter 1: Ambiguous argument values for parameter of type [com.arangodb.springframework.core.ArangoOperations] - did you specify the correct bean references as arguments?
    at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:756) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:218) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1341) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1187) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getSingletonFactoryBeanForTypeCheck(AbstractAutowireCapableBeanFactory.java:991) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryBean(AbstractAutowireCapableBeanFactory.java:865) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.isTypeMatch(AbstractBeanFactory.java:574) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:518) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:481) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:602) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:594) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:1226) ~[spring-context-5.1.9.RELEASE.jar:5.1.9.RELEASE]
    at org.springframework.boot.SpringApplication.getExitCodeFromMappedException(SpringApplication.java:865) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
    at org.springframework.boot.SpringApplication.getExitCodeFromException(SpringApplication.java:853) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
    at org.springframework.boot.SpringApplication.handleExitCode(SpringApplication.java:840) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
    at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:791) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:322) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1214) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1203) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
    at org.springframework.boot.SpringApplication$run.call(Unknown Source) [spring-boot-2.1.7.RELEASE.jar:2.1.7.RELEASE]
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) [groovy-2.5.7.jar:2.5.7]
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:115) [groovy-2.5.7.jar:2.5.7]
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:135) [groovy-2.5.7.jar:2.5.7]
    at com.softwood.arango.ArangoApplication.main(ArangoApplication.groovy:14) [main/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_181]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_181]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_181]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_181]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.1.7.RELEASE.jar:2.1.7.RELEASE]
a8jjtwal

a8jjtwal1#

所以最后我注意到我复制的示例没有反映最新版本的库等,所以我采用了最新的Docker映像3.4,并在依赖项中将Gradle应用程序版本更新为最新的库

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    implementation 'org.codehaus.groovy:groovy'
    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    compile 'com.arangodb:arangodb-spring-data:3.1.0'
    compile 'com.arangodb:arangodb-java-driver:5.0.7'
}

事情开始看起来更好了,但是他们改变了spring数据仓库接口defn,现在你需要两个类型-实体类和@id字段的类型id-否则代码将无法编译
public interface OrganisationRepository extends ArangoRepository<Organisation, String> {}
这允许保存工作-
但是,findOne操作采用Example.of并返回一个optional.so,因此在最新代码中,您必须在执行Optionic.get()以获取值之前测试完成的结果
所以我的简单CrudRunner运行操作现在看起来像这样,它编译、运行并返回以前保存的对象

@Override
public void run(final String... args) throws Exception {
    // first drop the database so that we can run this multiple times with the same dataset
    operations.dropDatabase()

    // save a single entity in the database
    // there is no need of creating the collection first. This happen automatically
    final Organisation vf = new Organisation(name:"Vodafone", inaugurated: 2000, webAddress:"vodafone.com")
    repository.save(vf)

    CollectionOperations coll= operations.collection(Organisation)

    CollectionPropertiesEntity props = coll.getProperties()
    println props.name

    // the generated id from the database is set in the original entity
    println(String.format("vf organisation saved in the database with id: '%s'", vf.id))

    // create an example from saved object and use to query the db - findOne returns Optional<T>
    Optional<Organisation> res = repository.findOne(Example.of(vf))
    assert res.isPresent()

    final Organisation foundOrg = res.get()

    repository.findOne()
    println(String.format("Found %s", foundOrg.name))

}

所以现在我们有了一个基本的工作版本的spring数据与arango。足以让你在道路上的最初'驼峰'我可以探索更远一点
我希望这可能会帮助任何其他人谁想要开始,并得到沮丧时,您的概念验证失败的工作。
注意.在docker服务器上的浏览器客户端中,您需要选择您创建的数据库(此处为“arango-demo”db)作为默认的登录系统数据库,而不是您的应用程序数据库。一旦您选择了正确的数据库,您就可以看到自动创建的集合以及该集合中的记录。

相关问题