我用IDEA创建一个SpringBoot项目,各种配置,mapper类和model类都检查了没有错,运行后控制台报错:

Field userMapper in com.ajax.service.J1902UserService required a bean of type ‘com.ajax.dao.J1902UserMapper’ that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
- Action:
- Consider defining a bean of type ‘com.zym_ajax.dao.J1902UserMapper’ in your configuration.

就是说我的dao类没有注入成功,我就在网上查了一下,是项目的启动类没有Mapper扫描包的注解。

类上加注解@MapperScan指明Mapper类所在包的位置供SpringBoot扫描就好啦。

@SpringBootApplication
@MapperScan("com.zym_ajax.dao")
public class ZymAjaxApplication {

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

更多推荐

springBoot项目Consider defining a bean of type 'xxx' in your configurati