Java 与Spring和Mybatis的交易
我有这个mapper-config.xml。游戏类中有DAO和BLM:Java 与Spring和Mybatis的交易,java,spring,spring-mvc,transactions,mybatis,Java,Spring,Spring Mvc,Transactions,Mybatis,我有这个mapper-config.xml。游戏类中有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
<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>
it.certimeter.nagima.blm.game.IBLMGame
需要传播\u,-it.fondsai.jeffs.core.exception.service.appl.JeffsServiceApplException
但我有一个错误:
嵌套异常为org.springframework.beans.factory.NoniqueBeandDefinitionException:未定义类型为[it.certimeter.nagima.blm.game.IBLMGame]的合格bean:应为单个匹配bean,但找到2:blmgamTarget,BLMGame
我错在哪里了?是的,本评论的问题。前几天我自己也遇到了这件事 这个问题带来了一种不好的代码味道,但是如果您想要一种解决方法,我建议如下: 转到@Autowire您的IBLMGame实例所在的位置。除了@Autowire注释外,还可以提供@Qualifier注释,并给出一个字符串值,该值表示实际需要连接的bean名称 因此,对于您的情况,它可能看起来像这样:
@Autowired
@Qualifier("BLMGameTarget") // you can substitute in "BLMGame" if that's the bean you want
IBLMGame iblmGame;
您有两个实现IBLMGame接口的bean,spring在将这些bean连接在一起时不知道选择哪个:非常感谢npm622。为什么你说它有一种不好的代码味道?“blmgametarge”和“BLMGame”听起来非常相关——几乎就像一个继承或实现了另一个一样。我冒昧地猜测,有一种方法可以重构您的代码,使这些具体的类中只有一个实现您正在自动连接的接口。或者,您可以自动将更特定于上下文的类关联为字段的类型。