springboot无法启动之service层无法找到dao层对象

 springboot启动后报错,显示如下:

Field discussPostMapper in com.example.niuke.service.DiscussPostService required a bean of type 'com.example.niuke.dao.DiscussPostMapper' that could not be found.

The injection point has the following annotations:
	- @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.example.niuke.dao.DiscussPostMapper' in your configuration.

也就是说service层要dao层的一个mapper对象,但是找不到

找了网上有人说的一种方法:在启动类中增加MapperScan注解,扫描dao包

@SpringBootApplication
@MapperScan("com.example.niuke.dao")

public class NiukeApplication
{

	public static void main(String[] args) {
		SpringApplication.run(NiukeApplication.class, args);
	}

}

结果出现了新的报错:

Property 'sqlSessionFactory' or 'sqlSessionTemplate' are required

换另一种全新的方法:在pom.xml文件中查看依赖:

        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.11</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>2.0.7</version>
        </dependency>

显然这里引入的是mybatis和mybatis-spring的依赖,将这两个依赖删除,替换成mybatis-springboot-starter依赖


<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.2.2</version>
</dependency>

然后在maven里面,先clean,然后install,最后刷新

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值