Field userMapper in org.sang.service.UserService required a bean of type 'org.sang.mapper.UserMapper' that could not be found.
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled. 2018-08-10 14:35:47.147 ERROR 58216 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
APPLICATION FAILED TO START
Description:
Field userMapper in org.sang.service.UserService required a bean of type 'org.sang.mapper.UserMapper' that could not be found.
Action:
Consider defining a bean of type 'org.sang.mapper.UserMapper' in your configuration.
Process finished with exit code 1
在application类上添加注解:@MapperScan(basePackages = "org.sang.mapper")
下载下来就改了下配置文件,报错,刚学习spring boot,什么原因报错?
需要在启动类的@EnableAutoConfiguration或@SpringBootApplication中添加exclude = {DataSourceAutoConfiguration.class},排除此类的autoconfig。启动以后就可以正常运行。
以上,网搜的,改好后运行,也报了题主同样的错误,但是加了楼上的注解,错误更多了。。。
package org.sang;
import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class}) @EnableScheduling//开启定时任务支持 @MapperScan(basePackages = "org.sang.mapper") public class BlogserverApplication {
public static void main(String[] args) {
SpringApplication.run(BlogserverApplication.class, args);
}
}

resources文件夹右击 mark directory as resources root,看了之前关闭的问题,IEDEA这样操作解决了。
@zuoee 我也遇到这个问题,发现是因为资源文件没被打包,从IDE层面去设置不如从代码层面去修改,我的解决方案是:在pom文件<resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> </resource>
更新mybatis框架到2.0.0之后,项目即可以运行
尝试过close上的做法,没有作用,而且看文件夹格式和pom文件,resource Root作者应该是已经修改过了