Bean name ambiguously matches the same Bean twice

I am trying to use spring-data-jpa and spring-data-mongodb. When deploying, several of my repositories are deployed until one (random each time) can deploy with an error

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()]"}}

It seems to coincide with the same interface - any idea of ​​what might happen?

Interface UserRepository

public interface UserRepository extends LocationRepository<User> { }

And LocationRepositoryis a common root interface for locations that looks like

@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);
}

My configuration I'm not too sure about

@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");
    }
}

Along with persistence.xmlaccording to the following - is this the right provider?

<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>
+4
source share
1 answer

, beans, Maven pom.xml . , Spring bean .

+2

Source: https://habr.com/ru/post/1659074/


All Articles