卡了4h小时了,springboot整合mybatis

server:
  port: 9090
spring:
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://localhost:3306/nhy?serverTimezone=GMT%2b8
    username: root
    password: 123456
mybatis:
  mapper-locations: classpath:mapper/*.xml  #扫描所有mybatis的xml文件
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.dao.UserDao">
    <resultMap id="userSearch" type="com.example.demo.pojo.userBean">
        <id column="id" property="id"></id>
        <result column="username" property="name"></result>
        <result column="password" property="pwd"></result>
        <result column="nickname" property="nickname"></result>
        <result column="email" property="email"></result>
        <result column="phone" property="phone"></result>
        <result column="address" property="address"></result>
    </resultMap>

    <select id="search"  resultMap="userSearch">
        select * from sys_user limit #{newPageNum},#{newPageSize};
    </select>
</mapper>

//@Mapper
public interface UserDao {
   //@Select(" select * from sys_user where username like concat('%',#{username},'%') limit  #{newPageNum},#{newPageSize};")
    List<UserBean> search(@Param("newPageNum") Integer pageNum,@Param("newPageSize") Integer pageSize,String username,String address);
   // @Select("select count(*) from sys_user")
    Integer finaAll();
}

img


一启动就报错,mapper-locations: classpath:mapper/*.xml 删了就好了,只用注解的话就没问题,应该是配置文件问题
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userController': Unsatisfied dependency expressed through field 'userService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Inject

boot用的2.7,mybatis-boot2.2

主要还是的mapper.xml的实体映射问题。


@SpringBootApplication
@MapperScan("com.example.demo.dao")
public class DemoApplication {
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

springboot 启动入口是否添加了扫描mapper配置,可以使用@MapperScan将mapper接口扫描进来。(单项目Model)

@MapperScan(value = "com.xxx.aaacommonsapi.mapper")
@SpringBootApplication( exclude = {
DataSourceAutoConfiguration.class})
public class XxxAdminApplication {

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

}