果然不看教程直接使用在遇到问题会懵逼,连解决问题都得搜半天还不一定能帮你解决了。。。

***************************
APPLICATION FAILED TO START
***************************
Description:
Field mapper in com.demo.service.impl.UserServiceImpl required a bean of type 'com.demo.mapper.UserMapper' that could not be found.
Action:
Consider defining a bean of type 'com.demo.mapper.UserMapper' in your configuration.

SpringBoot启动失败,告诉我Bean配置失败,楼主看了看  该用的注解都用上了  这是咋的回事嘞?

mapper(Dao层)

 package com.demo.mapper;

 import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Repository; import com.demo.domain.User; //@Component
@Repository
public interface UserMapper { public User gYeMian(User u); public int sYeMian(User u); }

service

package com.demo.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import com.demo.domain.User;
import com.demo.mapper.UserMapper;
import com.demo.service.UserService; @Service(value = "userService")
public class UserServiceImpl implements UserService{ @Autowired
private UserMapper mapper; @Override
public User gYeMian(User u) {
User user = mapper.gYeMian(u);
return user;
} @Override
public int sYeMian(User u) {
int i = mapper.sYeMian(u);
return i;
} }

controller

 package com.demo.controller;

 import javax.servlet.http.HttpServletRequest;

 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.ResponseBody; import com.demo.domain.User;
import com.demo.service.UserService; @Controller
@RequestMapping(value = "/uc")
public class UserController { @Autowired
private UserService userService; @ResponseBody
@RequestMapping("/stemp.htm")
private String sYeMian(String muBan, HttpServletRequest request){ User u = new User();
u.setMuBan(muBan);
System.out.println("muBan=" + muBan);
int i = userService.sYeMian(u); if (i>0){
return "存储成功";
}
return "存储失败";
} }

后来在网上看到网友说要用@Mapper注解,这才把问题解决了   至于具体原因,楼主还需要好好看看文档再来解释。

解决方案一:

mapper(Dao层)

 package com.demo.mapper;

 import org.apache.ibatis.annotations.Mapper;

 import com.demo.domain.User;

 @Mapper
public interface UserMapper { public User gYeMian(User u); public int sYeMian(User u); }

解决方案二:

Application(启动类)

 package com.demo;

 import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
@MapperScan(value = "com.demo.mapper")
public class App
{
public static void main(String[] args) throws Exception {
SpringApplication.run(App.class, args);
}
}

原因:在mybatis-spring-boot-autoconfigure的jar包中有一个类 MybatisAutoConfiguration,在这个类中的registerBeanDefinitions方法告诉了我们

 @Override
public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { logger.debug("Searching for mappers annotated with @Mapper"); ClassPathMapperScanner scanner = new ClassPathMapperScanner(registry); try {
if (this.resourceLoader != null) {
scanner.setResourceLoader(this.resourceLoader);
} List<String> packages = AutoConfigurationPackages.get(this.beanFactory);
if (logger.isDebugEnabled()) {
for (String pkg : packages) {
logger.debug("Using auto-configuration base package '{}'", pkg);
}
} scanner.setAnnotationClass(Mapper.class);
scanner.registerFilters();
scanner.doScan(StringUtils.toStringArray(packages));
} catch (IllegalStateException ex) {
logger.debug("Could not determine auto-configuration package, automatic mapper scanning disabled.", ex);
}
}

Spring Boot:Consider defining a bean of type '*.*.*' in your configuration解决方案的更多相关文章

  1. 记一个SpringBoot中属性注入失败的问题Consider defining a bean of type ''' in your configuration

    今天遇到的一个问题: 代码检查了好几次,都没有错误,但是启动时就会报错Consider defining a bean of type ''' in your configuration. 启动类在c ...

  2. 关于spring boot自动注入出现Consider defining a bean of type 'xxx' in your configuration问题解决方案

    搭建完spring boot的demo后自然要实现自动注入来体现spring ioc的便利了,但是我在实施过程中出现了这么一个问题,见下面,这里找到解决办法记录下来,供遇到同样的问题的同僚参考 Des ...

  3. 【spring boot】mybatis启动报错:Consider defining a bean of type 'com.newhope.interview.dao.UserMapper' in your configuration. 【Mapper类不能被找到】@Mapper 和@MapperScan注解的区别

    启动报错: 2018-05-16 17:22:58.161 ERROR 4080 --- Disconnected from the target VM, address: '127.0.0.1:50 ...

  4. Spring Cloud ZooKeeper集成Feign的坑1,错误:Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration.

    错误如下: ERROR 31473 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** A ...

  5. Consider defining a bean of type 'com.lvjing.dao.DeviceStatusMapper' in your configuration.

    "C:\Program Files\Java\jdk1.8.0_181\bin\java.exe" "-javaagent:C:\Program Files\JetBra ...

  6. springboot 工程启动报错之Consider defining a bean of type ‘XXX’ in your configuration.

    一.前言: 使用springboot自动注入的方式搭建好了工程,结果启动的时候报错了!!!,错误如下图: Description: Field userEntityMapper in com.xxx. ...

  7. Consider defining a bean of type 'package' in your configuration [Spring-Boot]

    https://stackoverflow.com/questions/40384056/consider-defining-a-bean-of-type-package-in-your-config ...

  8. Consider defining a bean of type 'XX.XX.XX.XX.mapper.XXMapper' in your configuration.

    今天构建一个springboot 项目,采用mybatis+mysql 然后就出现了这种错误....浪费我半天时间 Description: Field loginLogMapper in com.g ...

  9. Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration

    https://www.cnblogs.com/EasonJim/p/7546136.html 错误如下: ERROR 31473 --- [ main] o.s.b.d.LoggingFailure ...

随机推荐

  1. Efounds笔试

    Efounds的笔试~ 1.比较两个浮点数大小 一般不会直接用"=="或者"!="对两个浮点数进行比较. 判断两个浮点数float a 与 float b 是否 ...

  2. python与MySQL

    一.python与mysql交互 因版本不同python操作mysql有两个模块,python3不再支持MySQL-python,模块使用都一样: python2.7:MySQL-python pyt ...

  3. excel生成sql语句

    很多时候,我们想把excel中数据导入到数据库中. 方法有很多种,比如直接拷贝然后黏贴进编辑状态的框中,这种情况有个弊端,就是excel中每列的数据必须和数据库中一一对应,这个很难,基本上不太可能,数 ...

  4. java面向对象——类

    一.类 类(class)是构造对象的模板或蓝图.由类构造(construct)对象的过程称为创建类的实例(instance). 用 java 编写的所有代码都位于某个类的内部.标准的Java 库提供了 ...

  5. Django 发送邮件

    问题: 对于一些错误信息或用户注册账号的时候,需要给用户发送邮件进行验证. 以用户注册发邮件为例子,用户向后端提起注册,后端收到用户邮箱,对邮箱格式进行验证,然后发送邮件,邮件内容中包括邮件标题.邮件 ...

  6. .net Core连接MongoDB

    前两天在学习MongoDB相关的知识,做了个小Demo,大概是省份里面有多少所学校 连接MongoDB首先要通过Nuget添加一个MongoDB的包,下载此包 安装完毕后开始写代码了,创建一个省份实体 ...

  7. SVN同步时忽略特定文件或文件夹

    在MyEclipse中使用SVN同步的时候,经常会提示一些比如.classpath等不需要同步的配置文件,可以通过设置来忽略这一部分的文件或者文件夹. 1.选择菜单Window→Preferences ...

  8. android 自定义控件用的定时CountDownTimer

    定时执行在一段时候后停止的倒计时,在倒计时执行过程中会在固定间隔时间得到通知(译者:触发onTick方法), 下面的例子显示在一个文本框中显示一个30s倒计时: new CountdownTimer( ...

  9. flex基本概念

    基本使用 任何一个容器都可以指定为flex布局 .box { display: flex; } 行内元素也可以使用flex .box { display: inline-flex; } Webkit内 ...

  10. SQL性能优化的几点建议

    1. 索引:索引可以提高查询的速度,但不是使用带有索引的字段查询时,索引都会起作用,如下几种特殊情况下,有可能使用带有索引的字段查询时,索引没有起作用:1)使用LIKE关键字的查询语句 如果匹配字符串 ...