Reputation: 7511
I'm trying to use spring-data-jpa and spring-data-mongodb. On deploy, several of my repositories deploy, until one (a random one each time) fails to deploy with an error of
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 be matching the same interface twice - any idea of what might be happening?
The UserRepository
interface is
public interface UserRepository extends LocationRepository<User> { }
And LocationRepository
is a general 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, which I'm not overly confident in, is
@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 a persistence.xml
as per 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>
Upvotes: 4
Views: 694
Reputation: 87
I imagine both libraries have the same beans so you need add provided scope into your Maven pom.xml for one of those libraries. Looks like Spring is finding the same bean in multiple places.
Upvotes: 2