簡體   English   中英

與Spring和Mybatis的交易

[英]Transaction with Spring and Mybatis

我有這個mapper-config.xml.Game類有DAO和BLM:

<bean id="DAOGame" class="it.certimeter.nagima.dao.game.DAOGame">
    <property name="sqlSessionFactory" ref="sqlSessionFactory" />
</bean>

<bean id="BLMGameTarget" class="it.certimeter.nagima.blm.game.BLMGame">
    <property name="daoGame" ref="DAOGame" />
</bean>

和用於事務的bean:

<bean class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" id="BLMGame">
    <property name="proxyInterfaces">
        <list>
            <value>it.certimeter.nagima.blm.game.IBLMGame</value>
        </list>
    </property>
    <property name="transactionManager">
        <ref bean="transactionManager"/>
    </property>
    <property name="target">
        <ref bean="BLMGameTarget"/>
    </property>
    <property name="transactionAttributes">
        <props>
            <prop key="saveGame">PROPAGATION_REQUIRED, -it.fondsai.jeffs.core.exception.service.appl.JeffsServiceApplException</prop>
        </props>
    </property>
    <!-- <property name="anonymousAccess" value="true"/> -->
</bean>

但是我有這個錯誤:嵌套的異常是org.springframework.beans.factory.NoUniqueBeanDefinitionException:沒有定義類型[it.certimeter.nagima.blm.game.IBLMGame]的合格bean:期望的單個匹配bean,但發現2:BLMGameTarget, BLMGame

我在哪里錯了?

是的,本評論的問題。 前幾天我只是碰到這個。

這個問題帶來了不好的代碼味道,但是如果您要一種解決方法,我建議采取以下措施:

轉到您@Autowire IBLMGame實例的位置。 除了@Autowire批注之外,您還可以提供@Qualifier批注,並提供一個String值,該值表示您實際想要連接的bean名稱。

因此,對於您的情況,可能看起來像這樣:

@Autowired
@Qualifier("BLMGameTarget")  // you can substitute in "BLMGame" if that's the bean you want
IBLMGame iblmGame;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM