springboot+mybatis+mybatis plus 项目搭建问题复盘

背景:springboot+mybatis+mybatis plus 项目搭建问题复盘
问题汇总:
1、
Failed to configure a DataSource: ‘url’ attribute is not specified and no em
2、org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘bookServiceImpl’: Unsatisfied dependency expressed through field ‘baseMapper’; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘com.learn.mapper.BookMapper’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

等。

问题解析:
搭建时,遇到了上述等问题,通过各种途径,说配置@MapperScan,@Mapper,@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})等操作,但还是出现找不到url,生成不了bean等。

问题原因:
1、springboot的版本、mybatis版本、mybatis plus版本是否匹配;
2、@MapperScan 是否设置妥当。

此次搭建时主要遇到问题是版本不匹配。

准确配置后使用版本参考:
springboot:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.3.7.RELEASE</version>
</parent>

mybatis:

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.0.1</version>
</dependency>
<dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>3.5.6</version>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.47</version>
</dependency>

mybatis plus:

<dependency>
	<groupId>com.baomidou</groupId>
	<artifactId>mybatis-plus-boot-starter</artifactId>
	<version>3.3.2</version>
</dependency>

3、构建的项目少封装了配置文件。
pom.xml 文件中加入:

<build>
    <resources>
        <resource>
            <directory>src/main/java</directory>
            <includes>
                <include>**/*.xml</include>
            </includes>
        </resource>
        <resource>
            <directory>src/main/resources</directory>
            <includes>
                <include>**/*.properties</include>
                <include>**/*.yml</include>
                <include>**/*.xml</include>
            </includes>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

注:
对于版本冲突的另外一种解决方案:由于mybatis-plus已经集成了mybatis的依赖,所以可不单独配置,避免版本冲突。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值