SpringBoot 工程启动 tk.mybatis 绑定报错?

搜索了一些类似案例未解决,问题出在哪里?

1.> 错误提示:

Failed to bind properties under 'mapper' to tk.mybatis.mapper.entity.Config:

Reason: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [tk.mybatis.mapper.entity.Config]

Action:

Update your application's configuration

  1. pom.xml ,重点关注 “tk.mybatis”
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.12</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>cn.shq</groupId>
    <artifactId>springBoot_CRUD</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>springBoot_CRUD</name>
    <description>springBoot_CRUD</description>
    <properties>
    <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
        <java.version>1.8</java.version>
    </properties>
    <dependencies>
        <!--     thymeleaf   -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
        <!--      web      -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!--        mybatis-->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.2.0</version>
        </dependency>
        <!--      前端开发者工具  -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <!--        mysql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.25</version>
        </dependency>
        <!--       lombok插件-->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <!--        测试-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <!--        前端开始-->
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>jquery</artifactId>
            <version>3.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>layui</artifactId>
            <version>2.5.6</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap</artifactId>
            <version>4.5.2</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap-select</artifactId>
            <version>1.13.17</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap-datetimepicker</artifactId>
            <version>2.4.4</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>bootstrap-table</artifactId>
            <version>1.16.0</version>
        </dependency>
        <dependency>
            <groupId>org.webjars</groupId>
            <artifactId>momentjs</artifactId>
            <version>2.24.0</version>
        </dependency>
        <!--  前端结束-->
 
        <!--     lang包的增强版   -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.9</version>
        </dependency>
 
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper-spring-boot-starter</artifactId>
            <version>2.1.5</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.10</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>
 
 
 
    </dependencies>
 
    <build>
        <!-- 使得程序在执行过程中,能够解析到各个mapper.xml文件 。
                否则target目录下没有对应的mapper文件,程序不能正常执行。  -->
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.yml</include>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
                <filtering>false</filtering>
            </resource>
            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.css</include>
                    <include>**/*.js</include>
                    <include>**/*.html</include>
                    <include>**/*.png</include>
                    <include>**/*.jpg</include>
                    <include>**/*.properties</include>
                    <include>**/*.yml</include>
                    <include>**/*.xml</include>
                    <include>**/*.conf</include>
                </includes>
                <filtering>false</filtering>
            </resource>
        </resources>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>
 
</project>
  1. application.properties
# \u670D\u52A1\u5668\u8BBE\u7F6E\uFF1A  \u7AEF\u53E3\u53F7\u548C\u8BBF\u95EE\u8DEF\u5F84
server:
  port: 8088
  servlet:
    context-path: /shq
# \u6570\u636E\u6E90\u8BBE\u7F6E
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://192.168.31.226:3306/dhc_crud??serverTimezone=UTC
    username: root
    password: 123456
  thymeleaf:
    cache: false
    suffix: .html
  web:
    resources:
      static-locations: classpath:/templates/,classpath:/static/image/
# \u8BA9\u63A7\u5236\u53F0\u663E\u793A\u6267\u884C\u7684SQL\u8BED\u53E5
logging:
  level:
    cn:
      shq:
        mapper: debug
# mybatis\u914D\u7F6E
mybatis:
  type-aliases-package: cn.shq.model   # \u522B\u540D
  configuration:
    auto-mapping-behavior: full  #\u8BBE\u7F6E\u5168\u81EA\u52A8\u6620\u5C04
    use-column-label: true    # \u5217\u6807\u7B7E\u4EE3\u66FF\u5B57\u6BB5\u540D
#\u8BBE\u7F6Emapper\u7684\u8DEF\u5F84
  mapper-locations: classpath:cn/shq/mapper/*.xml 
阅读 705
avatarAI BotBETA

从你提供的错误信息来看,Spring Boot在尝试绑定mapper属性到tk.mybatis.mapper.entity.Config时遇到了问题。它找不到一个合适的转换器来将字符串转换为tk.mybatis.mapper.entity.Config类型。

在你的application.properties文件中,你似乎没有为tk.mybatismapper属性设置任何值。可能的问题是,Spring Boot试图读取这个属性,但是由于找不到它,所以尝试使用默认值,而这个默认值可能是一个字符串,而不是tk.mybatis.mapper.entity.Config类型的对象。

解决这个问题的方法可能有两种:

  1. 确保你的application.properties文件中包含tk.mybatismapper属性的正确设置。如果tk.mybatis.mapper.entity.Config类有默认的构造函数和必要的setter方法,那么你可能只需要提供一个字符串形式的配置路径。然而,由于我没有tk.mybatis.mapper.entity.Config类的具体信息,所以我无法给出具体的设置值。
  2. 如果你不需要在application.properties文件中设置tk.mybatismapper属性,你可以尝试在你的配置类中使用@ConfigurationProperties注解来忽略这个属性。例如:
@Configuration
@ConfigurationProperties(ignoreUnknownFields = true)
public class MybatisConfig {
    // 其他属性...
}

在这个例子中,ignoreUnknownFields = true会告诉Spring Boot忽略任何在application.properties文件中定义但在MybatisConfig类中不存在的属性。

以上都是基于我对你问题的理解给出的建议,由于我缺乏关于你的tk.mybatis.mapper.entity.Config类的具体信息,所以可能需要你进行一些调整。如果问题仍然存在,我建议你查看tk.mybatis的文档,看看是否有关于如何正确设置mapper属性的信息。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏