2016-03-21 18 views
1

私はこの例を実行しようとしています: https://spring.io/guides/gs/accessing-data-neo4j/ ビルドツールとしてMavenを使用しています。 以下のようなエラーが表示されます。neo4j:依存関係のためにタイプの修飾Beanが見つかりません

[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); 

} 

答えて

1

:構成で

を、あなたにも@EnableNeo4jRepositories注釈を追加する必要があります便利なように必要なコンポーネントをスピンアップするためにNeo4jConfigurationクラスを拡張します。

デフォルトでは、@EnableNeo4jRepositoriesは、現在のパッケージで、Spring Dataのリポジトリインタフェースのいずれかを拡張するインタフェースをスキャンします。プロジェクトのレイアウトに複数のプロジェクトがあり、リポジトリが見つからない場合は、別のルートパッケージをタイプ別にスキャンするようにSpring Data GemFireに安全に伝えるためにはbasePackageClasses=MyRepository.classを使用してください。

欠けている部分は、グラフデータベースサービスBeanです。この場合、ファイルベースのデータストアを作成して再利用するEmbeddedGraphDatabaseを使用しています(accessingdataneo4j.db)。

このように、Sprint Bootアプリケーションの設定を追加するクラスを作成する必要があります。それを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); 

} 

は、あなたがSpring GitHub repo上の完全なコードを見ることができます。

関連する問題