SpringBoot:Consider defining a bean of type 'com.wzw.blog.mapper.UserMapper' in your configuration.

1608 ワード

今日SpringBootを使用してMybatisを統合中にエラーが発生しました.
***************************
APPLICATION FAILED TO START
***************************

Description:

Field userMapper in com.wzw.blog.service.impl.UserServiceImpl required a bean of type 'com.wzw.blog.mapper.UserMapper' that could not be found.


Action:

Consider defining a bean of type 'com.wzw.blog.mapper.UserMapper' in your configuration.


ソリューション:一:@Mapperの使用
@Mapper
public interface UserMapper {

    public User getUserById(Integer uId);
}

二、@MapperScan(value=")を使う

@SpringBootApplication
@MapperScan(value="com.wzw.blog.mapper")
public class Application {

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