Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method 'sqlSessionFactory' threw exception; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\mavenwork\workspace\community\target\classes\mapper\user-mapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [E:\mavenwork\workspace\community\target\classes\mapper\user-mapper.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'User'. Cause: java.lang.ClassNotFoundException: Cannot find class: User
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658)
经检查,发现application.properties配置文件有错误(笔者手敲的,有字母敲错的失误问题),如下面:
(注释:)#ServerProperties
server.port=8080
server.servlet.context-path=/community
(注释:)#ThymeleafProperties
spring.thymeleaf.cache=false
(注释:)# DataSourceProperties
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/community?characterEncoding=utf-8&useSSL=false&serverTimezone=Hongkong
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.hikari.maximum-pool-size=15
spring.datasource.hikari.minimum-idle=5
spring.datasource.hikari.idle-timeout=30000
(注释:)# MybatisProperties classpath????classes
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=zom.nowcoder.community.entity #这里打错了,应该是com
mybatis.configuration.useGeneratedKeys=true
mybatis.configuration.mapUnderscoreToCamelCase=true
修改之后,运行成功!