2016-10-27 15 views
4

私はspring-data-jpaとspring-data-mongodbを使用しようとしています。デプロイでは、1(ランダム1たびに)Beanの名前があいまいで、同じBeanに2回マッチする

Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001414: Bean name is ambiguous. Name za.co.knonchalant.dead.dao.repositories.UserRepository resolves to beans: 
    - CdiRepositoryBean: type='za.co.knonchalant.dead.dao.repositories.UserRepository', qualifiers=[@javax.enterprise.inject.Default(), @javax.enterprise.inject.Any()], 
    - CdiRepositoryBean: type='za.co.knonchalant.dead.dao.repositories.UserRepository', qualifiers=[@javax.enterprise.inject.Default(), @javax.enterprise.inject.Any()]"}} 

のエラーで配備に失敗するまで、私のリポジトリのいくつかは、展開それは二度同じインターフェイスを一致しているようだ - が起こっかもしれないものの任意のアイデア?

UserRepositoryインタフェースは

public interface UserRepository extends LocationRepository<User> { } 

そしてLocationRepositoryである私が

あり、中に過度に自信がないんだけど私の設定、

@NoRepositoryBean 
public interface LocationRepository<T> extends JpaRepository<T, String> { 
    List<T> findByPositionWithin(Circle c); 

    List<T> findByPositionNear(Point p, Distance distance); 

    List<T> findByPositionWithin(Box b); 
} 

のように見えること、場所のための一般的なルートインタフェースです
@Configuration 
@EnableJpaRepositories 
public class CdiConfig { 
    @Produces 
    @Dependent 
    @PersistenceContext(unitName = "mongo-ogm") 
    public EntityManager entityManager; 

    public 
    @Bean 
    Mongo mongo() throws Exception { 
     return new Mongo("localhost"); 
    } 

    @Produces 
    public @Bean MongoTemplate mongoTemplate() throws Exception { 
     return new MongoTemplate(mongo(), "mydatabase"); 
    } 
} 

persistence.xml次のように - これは適切なプロバイダですか?

<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> 
    <persistence-unit name="mongo-ogm" transaction-type="JTA"> 
     <provider>org.hibernate.ogm.jpa.HibernateOgmPersistence</provider> 
     <exclude-unlisted-classes>false</exclude-unlisted-classes> 
     <properties> 
      <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/> 
      <property name="hibernate.ogm.datastore.database" value="database"/> 
      <property name="hibernate.ogm.datastore.host" value="localhost"/> 
      <property name="hibernate.ogm.datastore.provider" value="MONGODB"/> 
      <property name="hibernate.ogm.datastore.create_database" value="true"/> 
     </properties> 
    </persistence-unit> 
</persistence> 
+0

あなたのUserRepository用のコードを含めることができればよいでしょう。 – megalucio

+0

あなたは 'spring-data-jpa'と' spring-data-mongodb'を使っていますか?多分 'spring-data-jpa'は' Jpa Repository Bean'と 'MonogRepository' Beanという' spring-data-mongodb'を生成していますか?あなたの設定を追加できますか? – Pau

+0

私は - 私はコードの近くになるとすぐに設定を追加します、私はそうではないでしょうが、これらのライブラリの両方が必要ですか? –

答えて

2

私は両方のライブラリが同じBeanを持っていると思うので、それらのライブラリの1つのMaven pom.xmlに提供されたスコープを追加する必要があります。 Springが複数の場所で同じBeanを見つけているように見えます。

+0

そのBeanは私自身のものですから、私のデータレイヤーにしか存在しません(これは一度だけ含まれています) –

関連する問題