<bean id="legacyDataSource" name="legacydb" class="org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init="true">
<property name="driverClassName" value="${jdbc.legacy.driverClassName}" />
<property name="url" value="${jdbc.legacy.url}" />
<property name="username" value="${jdbc.legacy.username}" />
<property name="password" value="${jdbc.legacy.password}" />
</bean>
<bean id="ls360DataSource" name="Ls360db" class="org.springframework.jdbc.datasource.DriverManagerDataSource" lazy-init="true" >
<property name="driverClassName" value="${jdbc.ls360.driverClassName}" />
<property name="url" value="${jdbc.ls360.url}" />
<property name="username" value="${jdbc.ls360.username}" />
<property name="password" value="${jdbc.ls360.password}" />
</bean>
<bean id="legacyTransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="legacyEmf"/>
</bean>
<bean id="ls360TransactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="ls360Emf"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="legacyEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
<property name="dataSource" ref="legacyDataSource" />
<property name="jpaVendorAdapter" ref="vendorAdaptor" />
<property name="packagesToScan" value="com.softech.ls360.integration.regulators.plcb.domain"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean id="ls360Emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" >
<property name="dataSource" ref="ls360DataSource" />
<property name="jpaVendorAdapter" ref="vendorAdaptor" />
<property name="packagesToScan" value="com.softech.ls360.integration.regulators.plcb.domain"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<context:component-scan base-package="....db" />
@Service("dbManager")
@Repository
@Transactional
public class DatabaseManager {
@PersistenceContext
@Qualifier("legacyEmf")
private EntityManager legacyEm;
@PersistenceContext
@Qualifier("ls360Emf")
private EntityManager ls360Em;
@SuppressWarnings("unchecked")
@Transactional(readOnly=true)
public List<Object> getResultList(String query, Class mappingClass) throws Exception {
//Query emQuery = legacyEm.createNativeQuery(query, mappingClass);
//return emQuery.getResultList();
return null;
} //end of findTraineeFromLegacy()
}
Error creating bean with name 'dbManager': Injection of persistence
dependencies failed; nested exception is
org.springframework.beans.factory.NoUniqueBeanDefinitionException:
No qualifying bean of type [javax.persistence.EntityManagerFactory] is defined:
expected single matching bean but found 2: legacyEmf,ls360Emf
为什么我会犯这个错误。我该怎么解决呢?
谢谢
我今天也有同样的问题。解决方法如下:
首先,我向@PersistenceContext的两个实体管理器属性添加了参数unitName:
@PersistenceContext(unitName="appPU")
@Qualifier(value = "appEntityManagerFactory")
private EntityManager appEntityManager;
@PersistenceContext(unitName="managerPU")
@Qualifier(value = "managerEntityManagerFactory")
private EntityManager managerEntityManager;
在我的配置文件中,我为bean定义添加了一个属性persistenceUnitName:
<bean id="appEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource1" />
<property name="persistenceUnitName" value="appPU" />
<property name="packagesToScan" value="br.com.app.domain" />
...
</bean>
<bean id="managerEntityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource2" />
<property name="persistenceUnitName" value="managerPU" />
<property name="packagesToScan" value="br.com.app.domain" />
...
</bean>
问题内容: 我是spring spring 3.2。这是我的配置文件 这是我的课 现在,当我朗读代码时,出现以下错误 为什么我收到此错误。我该如何解决? 谢谢 问题答案: 我今天有同样的问题。解决了以下问题: 首先,我将参数unitName添加到@PersistenceContext到两个实体管理器属性: 在我的配置文件中,我向bean定义添加了一个属性persistenceUnitName:
我有两个实体管理器配置用于两个单独的数据库,但当我尝试自动连接实体管理器来配置GraphQLExecutor bean时,我得到一个异常,指出有两个bean符合条件,尽管我在PersistenceContext中指定了一个单元名。 例外情况 注射 pom.xml
我有这个超级班: 我想确定我完全理解了解决方案。通过,我给类DAOBase指定了特定的名称“daoBaseBeanname”,应用程序可以用它来标识类DAOBase,这样就不会把它与扩展DAOBase的其他类混淆了。对吗? 谢谢你。
我有这个超级班: 谢谢你。
我有一个java项目,它将Spring Boot与JPA结合使用,并将Hibernate用于数据库。我正在尝试建立一个访问数据库的微服务。(我不熟悉微服务和Spring Boot)。 以下是主要课程: IGmCircularsDAO. class: GMCircularsDAOImpl。类别: ParentDAO。班 循环服务。班 当我运行这段代码时,我遇到了以下错误,我已经陷入其中一段时间了。