SpringBoot integrates MyBatis, startup project, error shows that Mapper cannot be found
***************************
APPLICATION FAILED TO START
***************************
Description:
Field userListMapper in com.example.demo.service.UserService required a bean of type "com.example.demo.mybatis.UserListMapper" that could not be found.
Action:
Consider defining a bean of type "com.example.demo.mybatis.UserListMapper" in your configuration.
I"ve been looking for it all day, but I still can"t find the problem. Here"s a simplified demo, I wrote. Can you help me see what"s wrong? The purpose of
is to query data from the database.
DemoApplication
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
@SpringBootApplication
@ComponentScan(value = "com.example.demo")
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
User
package com.example.demo.model;
public class User {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
UserListMapper
package com.example.demo.mybatis;
import com.example.demo.model.User;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public interface UserListMapper {
List<User> findAllUsers();
}
UserListMapper.xml
<?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.mybatis">
<select id="findAllUsers" resultType="com.example.demo.model.User">
select id, name from User
</select>
</mapper>
UserService
package com.example.demo.service;
import com.example.demo.mybatis.UserListMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserService {
@Autowired
private UserListMapper userListMapper;
}
application.yml
spring:
datasource:
url:
username:
password:
driver-class-name:
hikari:
minimum-idle: 10
maximum-pool-size: 100
Thank you very much!