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

***************************
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. Hive 多分隔符的使用 (转载)

    方法一)通过org.apache.hadoop.hive.contrib.serde2.RegexSerDe格式的serde. 1) 建表语句 #指定以^|~作为分隔符 CREATE TABlE ta ...

  2. java学习总结之文件操作--ByteArrayOutputStream的用法

    ByteArrayOutputStream类是在创建它的实例时,程序内部创建一个byte型别数组的缓冲区, 然后利用ByteArrayOutputStream和ByteArrayInputStream ...

  3. ASPNET5 依赖注入(Dependency Injection)

    依赖注入一直是asp.net web框架(Web API,SignalR and MVC)中不可或缺的一部分,但是在以前,这个框架都是各自升级,都有各自的依赖注入实现方式,即使Katana项目想通过O ...

  4. 浅析final关键字

    浅析final关键字 final单词字面意思是"最终的,不可更改的".所以在java中final关键字表示终态,即最终的状态,"这个东西不能被改变". fina ...

  5. Windows 性能搜集【perfmon】

    为方便问题发生后,问题原因的分析排查,我们可以在服务器中事先开启logman功能搜集服务器的性能数据,方便故障发生后,问题原因的分析排查 Windows服务器部署Permon性能搜集器: 1.使用管理 ...

  6. java中String的.trim()方法

    该方法去除两边的空白符 原理: 看看源码实现 public String trim() { int len = value.length; ; char[] val = value; /* avoid ...

  7. 流API--流的映射

    很多时候,将一个流的元素映射到另外一个流很有帮助.映射操作最具代表的就是map()方法.实际编码中,我们会经常用到,所以这里专门整理一篇博客. 考虑如下情景,对于一个包含了姓名,电话,年龄等属性构成的 ...

  8. Asp.net core 2.0.1 Razor 的使用学习笔记(一)

    环境:vs2017 版本:15.5.6 一.新建项目 1.文件>新建>项目>Visual c#>.NET Core>ASP.NET Core Web应用程序(“.NET ...

  9. IIS使用十大原则,(IIS过期时间,IIS缓存设置) 【转载】

    1. 自定义错误页虽然自定义错误页很简单,但只有少数管理员有效地利用了它.管理员可以在MMC中将HTTP错误信息映像到服务器上的绝对URL或是某个文件,更为详细的信息可以在这里找到.如果你嫌这太麻烦, ...

  10. java web response提供文件下载功能

    */ .hljs { display: block; overflow-x: auto; padding: 0.5em; color: #333; background: #f8f8f8; } .hl ...