VBlog icon indicating copy to clipboard operation
VBlog copied to clipboard

Field userMapper in org.sang.service.UserService required a bean of type 'org.sang.mapper.UserMapper' that could not be found.

Open isSmallStudent opened this issue 7 years ago • 6 comments

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

isSmallStudent avatar Aug 10 '18 06:08 isSmallStudent

在application类上添加注解:@MapperScan(basePackages = "org.sang.mapper")

Ozal220 avatar Aug 17 '18 08:08 Ozal220

image image 下载下来就改了下配置文件,报错,刚学习spring boot,什么原因报错?

zuoee avatar Aug 30 '18 06:08 zuoee

需要在启动类的@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);
}

}

image image

zuoee avatar Aug 30 '18 06:08 zuoee

resources文件夹右击 mark directory as resources root,看了之前关闭的问题,IEDEA这样操作解决了。

zuoee avatar Aug 30 '18 07:08 zuoee

@zuoee 我也遇到这个问题,发现是因为资源文件没被打包,从IDE层面去设置不如从代码层面去修改,我的解决方案是:在pom文件标签内增加一个资源节点: <resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> </resource>

wanxu2019 avatar Oct 22 '18 08:10 wanxu2019

更新mybatis框架到2.0.0之后,项目即可以运行

尝试过close上的做法,没有作用,而且看文件夹格式和pom文件,resource Root作者应该是已经修改过了

zau11berer avatar Mar 20 '21 09:03 zau11berer