org.springframework.beans.factory.NoUniqueBeanDefinitionException

时间:2013-10-06 19:53:23

标签: java spring-3

堆栈跟踪:

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [org.vliv.dao.MySqlLogDao] is defined: expected single matching bean but found 2: mySqlLogDaoImpl,mySqlLogDao

Java代码:

public interface MysqlDao {
    public void regstr();
}

@Repository
@Transactional
public class MysqlDaoImpl { 
    public void regstr() {}
}

@Controller
public class Brand {
    @Autowired
    MySqlDao mySqlDao;//gives exception
}

1 个答案:

答案 0 :(得分:1)

异常非常清楚。应用程序上下文中存在2个bean,它们实现了连接到控制器的接口。

Spring并不知道你真正想要的是哪一个,所以它会抛出异常。尝试使用@Qualifier注释来指示您真正想要的实现:

请参阅此处的api文档:

http://docs.spring.io/spring/docs/3.1.4.RELEASE/javadoc-api/org/springframework/beans/factory/annotation/Qualifier.html