mybatis封装dao servcie时碰到expected single matching bean but found 2:

原创 2015年11月19日 15:08:33
</pre>package com.levelappro.web.core.common.service;import java.util.List;import javax.annotation.Resource;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.transaction.annotation.Transactional;import com.levelappro.web.core.common.mybatis.dao.IMybatisBaseDao;import com.levelappro.web.core.common.mybatis.query.MybatisExample;import com.levelappro.web.core.common.page.PageList;/** * DAO支持类实现 *  * @author ThinkGem * @version 2013-05-15 * @param <T> */@Transactional(readOnly = true)public abstract class IMybatisService<Dao extends IMybatisBaseDao<T>, T> {<span style="white-space:pre">	</span>/**<span style="white-space:pre">	</span> * 持久层对象<span style="white-space:pre">	</span> */<span style="white-space:pre">	</span>@Autowired<span style="white-space:pre">	</span>protected Dao dao;<span style="white-space:pre">	</span>/**<span style="white-space:pre">	</span> * 获取单条数据<span style="white-space:pre">	</span> * <span style="white-space:pre">	</span> * @param id<span style="white-space:pre">	</span> * @return<span style="white-space:pre">	</span> */<span style="white-space:pre">	</span>public T getById(String id) {<span style="white-space:pre">		</span>return dao.getById(id);<span style="white-space:pre">	</span>}<span style="white-space:pre">	</span>/**<span style="white-space:pre">	</span> * 查询所有数据列表<span style="white-space:pre">	</span> * <span style="white-space:pre">	</span> * @param entity<span style="white-space:pre">	</span> * @return<span style="white-space:pre">	</span> */<span style="white-space:pre">	</span>public List<T> findAll() {<span style="white-space:pre">		</span>return dao.findAll();<span style="white-space:pre">	</span>}<span style="white-space:pre">	</span>/**<span style="white-space:pre">	</span> * 分页查询<span style="white-space:pre">	</span> * <span style="white-space:pre">	</span> * @param entity<span style="white-space:pre">	</span> * @return<span style="white-space:pre">	</span> */<span style="white-space:pre">	</span>public PageList<T> findByPage(MybatisExample example, PageList<T> page) {<span style="white-space:pre">		</span>List<T> list = dao.findByPage(example);<span style="white-space:pre">		</span>page.setResultList(list);<span style="white-space:pre">		</span>page.setTotalCount(dao.count(example));<span style="white-space:pre">		</span>return page;<span style="white-space:pre">	</span>}<span style="white-space:pre">	</span>/**<span style="white-space:pre">	</span> * 插入数据<span style="white-space:pre">	</span> * <span style="white-space:pre">	</span> * @param entity<span style="white-space:pre">	</span> * @return<span style="white-space:pre">	</span> */<span style="white-space:pre">	</span>public int insert(T entity) {<span style="white-space:pre">		</span>return dao.insert(entity);<span style="white-space:pre">	</span>}<span style="white-space:pre">	</span>/**<span style="white-space:pre">	</span> * 更新数据<span style="white-space:pre">	</span> * <span style="white-space:pre">	</span> * @param entity<span style="white-space:pre">	</span> * @return<span style="white-space:pre">	</span> */<span style="white-space:pre">	</span>public int update(T entity) {<span style="white-space:pre">		</span>return dao.update(entity);<span style="white-space:pre">	</span>}<span style="white-space:pre">	</span>/**<span style="white-space:pre">	</span> * 删除数据<span style="white-space:pre">	</span> * <span style="white-space:pre">	</span> * @param id<span style="white-space:pre">	</span> * @see public int delete(T entity)<span style="white-space:pre">	</span> * @return<span style="white-space:pre">	</span> */<span style="white-space:pre">	</span>public int delete(T entity) {<span style="white-space:pre">		</span>return dao.delete(entity);<span style="white-space:pre">	</span>}<span style="white-space:pre">	</span>/**<span style="white-space:pre">	</span> * 批量删除<span style="white-space:pre">	</span> * <span style="white-space:pre">	</span> * @param list<span style="white-space:pre">	</span> */<span style="white-space:pre">	</span>public int deleteBatch(final List<T> list) {<span style="white-space:pre">		</span>return dao.deleteBatch(list);<span style="white-space:pre">	</span>}<span style="white-space:pre">	</span>/**<span style="white-space:pre">	</span> * 查询总数<span style="white-space:pre">	</span> */<span style="white-space:pre">	</span>public int count(MybatisExample example) {<span style="white-space:pre">		</span>return dao.count(example);<span style="white-space:pre">	</span>}<span style="white-space:pre">	</span>/**<span style="white-space:pre">	</span> * 条件查询所有数据列表(不分页)<span style="white-space:pre">	</span> * <span style="white-space:pre">	</span> * @param entity<span style="white-space:pre">	</span> * @return<span style="white-space:pre">	</span> */<span style="white-space:pre">	</span>public List<T> findList(MybatisExample example) {<span style="white-space:pre">		</span>return dao.findList(example);<span style="white-space:pre">	</span>}<p>}</p><p></p><p>一开始这样设计baseservice,结果继承它的时候,启动报这个错,expected single matching bean but found 2:iLinksDao </p><p>iOrigsvrinfoDao注解不能用。。。。<span style="color: rgb(51, 51, 51); font-family: arial, 宋体, sans-serif, tahoma, 'Microsoft YaHei'; font-size: 14px; line-height: 24px; background-color: rgb(243, 255, 236);">因为你的接口有多个不同的实现类,spring容器不知道要给你注入哪个</span>网上找的加<span style="white-space:pre">	</span>@Qualifier也不管用。</p><p>没办法 最后只能改成这样,不使用注解</p><p><pre name="code" class="java">/**
	 * 持久层对象
	 */
	// @Autowired
	// protected Dao dao;
	public abstract IMybatisBaseDao<T> getDao();

	/**
	 * 获取单条数据
	 * 
	 * @param id
	 * @return
	 */
	public T getById(String id) {
		return this.getDao().getById(id);
	}
。。。继承这个baseService给dao
@Service
@Transactional
public class LinksService extends IMybatisService<Links>{

	@Autowired
	private ILinksDao iLinksDao;

	@Override
	public IMybatisBaseDao<Links> getDao() {
		return iLinksDao;
	}

}
还不知道用@Autowired 的话怎么解决那个问题,在研究下。。。。



版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

expected single matching bean but found 2

原文链接:http://blog.csdn.net/kirrin/article/details/47831845 [java] view plain copy print? //代...

expected '<document start>', but found BlockMappingStart in 'reader', line 13, column 1:nimbus.host:

具体错误信息如下:/bin/java Exception in thread "main" java.lang.ExceptionInInitializerError at backt...

hive 启动报错 Found class jline.Terminal, but interface was expected

[ERROR] Terminal initialization failed; falling back to unsupported java.lang.IncompatibleClassChang...

Found interface org.apache.hadoop.mapreduce.TaskAttemptContext, but class was expected

当本地编译测试过的mapreduce程序放到集群上跑则报以下错误 15/12/24 14:19:36 INFO mapreduce.JobSubmitter: Submitting tokens f...
  • doegoo
  • doegoo
  • 2015-12-24 15:07
  • 1060

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element

log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment)...

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element

- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for eleme...

error: macro "min" passed 3 arguments, but takes just 2 error: expected ‘)’ before ‘const’ 解决方法

最近在ubuntu下编译一个c++的solution,好几个project都得到如下的奇怪错误: In file included from /usr/include/c++/4.6/bit...

No matching bean of type [com.spw.service.UserService] found for dependency

在spring开发过程中遇到了这个错误,@Autowired自动化配置bean的项目启动的时候报错了 2016-8-3 23:02:04org.apache.catalina.core.Standa...

git pull时遇到git pull error :error: remote ref is at but expected问题的解决办法

今天在拉取项目新版本的代码时,遇到了一个问题,对项目最新的代码进行git pull,报错:error: cannot lock ref 'xxx': ref xxx is at (一个commitID...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)