Java neo4j:未找到依赖项类型的符合条件的bean

Java neo4j:未找到依赖项类型的符合条件的bean,java,spring,maven,neo4j,Java,Spring,Maven,Neo4j,我正在尝试运行以下示例: 我使用Maven作为构建工具。 我得到的错误如下: [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.3.RELEASE:run (default-cli) on project gs-accessing-data-neo4j: An exception occurred while running. null: InvocationTargetExc

我正在尝试运行以下示例: 我使用Maven作为构建工具。 我得到的错误如下:

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.3.3.RELEASE:run (default-cli) on project gs-accessing-data-neo4j: An exception occurred while running. null: InvocationTargetException: Error creating bean with name 'demo' defined in hello.Application: Unsatisfied dependency expressed through constructor argument with index 0 of type [hello.PersonRepository]: No qualifying bean of type [hello.PersonRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [hello.PersonRepository] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {} -> [Help 1]
有什么问题

这是我的PersonRepository.java文件:

package hello;

import java.util.List;
import org.springframework.data.neo4j.config.EnableNeo4jRepositories;

import org.springframework.data.repository.CrudRepository;

@EnableNeo4jRepositories(basePackageClasses=CrudRepository.class)
public interface PersonRepository extends CrudRepository<Person, String>
{

    Person findByName(String name);

    List<Person> findByTeammatesName(String name);

}
包你好;
导入java.util.List;
导入org.springframework.data.neo4j.config.EnableNeo4jRepositories;
导入org.springframework.data.repository.crudepository;
@EnableNeo4jRepositories(basePackageClasses=crudepository.class)
公共接口PersonRepository扩展了Crudepository
{
Person findByName(字符串名称);
列出FindByteMatesName(字符串名称);
}

如果仔细阅读本教程,您将看到:

在配置中,您需要添加
@EnableNeo4jRepositories
注释,并扩展
Neo4jConfiguration
类以方便地启动所需的组件

默认情况下,
@EnableNeo4jRepositories
将扫描当前包以查找扩展Spring数据的存储库接口之一的任何接口。使用它的
basePackageClasses=MyRepository.class
可以安全地告诉Spring Data GemFire,如果您的项目布局有多个项目,并且它找不到您的存储库,则可以按类型扫描不同的根包

缺少的一部分是图形数据库服务bean。在本例中,您使用的是
EmbeddedGraphDatabase
,它在
accessingdataneo4j.db
中创建并重用基于文件的数据存储

因此,您需要编写一个类来添加Sprint引导应用程序的配置。让我们称之为
ApplicationConfig.java
。将教程中的内容转化为代码,我们得出以下结论:

package hello;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.config.Neo4jConfiguration;

@Configuration
@EnableNeo4jRepositories
class ApplicationConfig extends Neo4jConfiguration {

    public ApplicationConfig() {
        setBasePackage("hello");
    }

    @Bean
    GraphDatabaseService graphDatabaseService() {
        return new GraphDatabaseFactory().newEmbeddedDatabase("accessingdataneo4j.db");
    }
}
如果将此类添加到
hello
包中,应用程序将正常运行

请注意,您应该保留本教程中定义的
PersonRepository
,如下所示:

package hello;

import java.util.List;

import org.springframework.data.repository.CrudRepository;

public interface PersonRepository extends CrudRepository<Person, String> {

    Person findByName(String name);

    List<Person> findByTeammatesName(String name);

}
包你好;
导入java.util.List;
导入org.springframework.data.repository.crudepository;
公共接口PersonRepository扩展了Crudepository{
Person findByName(字符串名称);
列出FindByteMatesName(字符串名称);
}

作为旁注,您可以在上看到它的完整代码