admin管理员组文章数量:1794759
Spring Boot错误:Consider defining a bean of type '*.*.Dao' in your configuration
SpringBoot在启动项目的时候遇到了以下情况:
APPLICATION FAILED TO START *************************** Description: Field sysUserDao in com.iamapsycho.service.impl.SysUserServiceImpl required a bean of type 'com.iamapsycho.dao.SysUserDao' that could not be found. Action: Consider defining a bean of type 'com.iamapsycho.dao.SysUserDao' in your configuration.SpringBoot启动失败,告诉我Bean配置失败,为什么报错呢?
Controller:
package com.iamapsycho.controller; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.iamapsycho.entity.SysUser; import com.iamapsycho.service.SysUserService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @Controller @Api(value = "sysUser接口") @RequestMapping("/sysuser") public class SysUserController { @Autowired SysUserService sysUserService; @ResponseBody @RequestMapping(value="/getList", method = { RequestMethod.GET, RequestMethod.POST }) @ApiOperation(value="获取用户列表", notes="用户列表") public List<SysUser> getList(){ List<SysUser> list = sysUserService.getList(); return list; } }Service:
package com.iamapsycho.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.iamapsycho.dao.SysUserDao; import com.iamapsycho.entity.SysUser; import com.iamapsycho.service.SysUserService; @Service public class SysUserServiceImpl implements SysUserService { @Autowired SysUserDao sysUserDao; @Override public List<SysUser> getList() { return sysUserDao.getList(); } }Dao:
package com.iamapsycho.dao; import java.util.List; import com.iamapsycho.entity.SysUser; public interface SysUserDao { List<SysUser> getList(); }在网上看到网友说要用@Mapper注解,这才把问题解决了 ,至于具体原因,需要通过文档来解释。
解决方案一: Dao层 添加:@Mapper
package com.iamapsycho.dao; import java.util.List; import org.apache.ibatis.annotations.Mapper; import com.iamapsycho.entity.SysUser; @Mapper public interface SysUserDao { List<SysUser> getList(); }解决方案二(强烈建议使用): Application(启动类) 添加:@MapperScan(value = “com.iamapsycho.dao”)
package com.iamapsycho; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication @MapperScan(value = "com.iamapsycho.dao") public class Application { public static void main(String[] args) { SpringApplication.run(Application.class, args); } }作者:iamapsycho 来源:CSDN 原文:blog.csdn/ampsycho/article/details/86243817 版权声明:本文为博主原创文章,转载请附上博文链接!
本文标签: 错误definingbeanbootspring
版权声明:本文标题:Spring Boot错误:Consider defining a bean of type &#039;*.*.Dao&#039; in your configuration 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1686552364a81033.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论