2017-02-15 7 views
0

のための豆を修飾:春ブーツ1.5.1、春データのMongoDBはありません、私はMavenの依存関係以下を追加している私のSpringBoot 1.5.1プロジェクトでは、リポジトリ

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-data-mongodb</artifactId> 
</dependency> 

と春データのMongoDBリポジトリを作成しました:

package com.example.domain.repository.decision.parameter; 

@Repository 
public interface CustomerRepository extends MongoRepository<DecisionAnalysisParameter, String> { 
} 

これは私のモデルである:

@Document(collection = "decision_analysis_parameter") 
public class DecisionAnalysisParameter implements Serializable { 

    private static final long serialVersionUID = 1493180175756424789L; 

    @Id 
    private String id; 

    @NotNull 
    private Long decisionId; 

    private Set<BaseQuery> characteristicFilterQueries; 

    private Set<Long> sortCriteriaIds; 

    private Direction sortWeightCriteriaDirection; 

    private Direction sortTotalVotesCriteriaDirection; 

    private Map<String, Double> sortCriteriaCoefficients; 

    private Long sortCharacteristicId; 

    private Direction sortCharacteristicDirection; 

    private String sortDecisionPropertyName; 

    private Direction sortDecisionPropertyDirection; 

    private Set<Long> excludeChildDecisionIds; 

    private Set<Long> includeChildDecisionIds; 

    private Long userId; 

    private Integer pageNumber; 

    private Integer pageSize; 

... 
} 

今私が正常に注入することができ

@Autowired 
private MongoTemplate mongoTemplate; 

このオブジェクトのコレクションを操作します。

しかし、私は注入しようとすると、私のアプリケーションは失敗します。

@Autowired 
private CustomerRepository customerRepository; 

次の例外を除いて:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.example.CustomerRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)} 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1486) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1104) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) 
    ... 56 common frames omitted 

これは私の設定クラスです:また

@Configuration 
@ComponentScan("com.example") 
@EnableMongoRepositories(basePackages = "com.example.domain.repository") 
@SpringBootApplication 
public class TestConfig { 
} 

、私が使用Neo4jリポジトリは正常に動作しています。それを修正するには?

答えて

1

複数のSpringデータモジュール(あなたのケースではNeo4J + MongoDB)を使用している場合は、両方のタイプのリポジトリに対して厳密な設定を行う必要があります。例:

@Configuration 
@ComponentScan("com.example") 
@EnableMongoRepositories(basePackages = "com.example.domain.repositories.mongodb") 
@EnableNeo4jRepositories(basePackages = "com.example.domain.repositories.neo4j") 
@SpringBootApplication 
public class TestConfig { 
} 
0

あなたのCustomerRepositoryは正しいパッケージにはありません。現在はcom.exampleパッケージです。

@EnableMongoRepositories(basePackages = "com.example.domain.repository") 
basePackagesEnableMongoRepositoriesから注釈を一致または CustomerRepositoryパッケージにアノテーション basePackage値を更新するためにリポジトリを移動

関連する問題