Description: Field mapper in com.kaigejava.kgblog,service.impl.UserServiceImpl required a bean of type 'com.kaigejava.kgblog.dao.UserDao' that could not be found. Action: Consider defining a bean of type 'com.kaigejava.kgblog.dao.UserDao' in your configuration.
SpringBoot启动失败,告诉我Bean配置失败,楼主看了看 该用的注解都用上了 这是咋的回事嘞?
先看错误的:
代码语言:javascript复制//@Component
@Repository
public interface UserMapper {
int insert(UserDomain record);
List<UserDomain> selectUsers();
}
这两个注解都是用了,为什么还会报错呢?
查询:
解决方案一:
后来在网上看到网友说要用@Mapper注解,这才把问题解决了 至于具体原因,楼主还需要好好看看文档再来解释。
于是修改:
代码语言:javascript复制@Mapper
public interface UserDao {
int insert(UserDomain record);
List<UserDomain> selectUsers();
}
重新启动,启动正常。访问ok.
解决方案二:
先看失败之前的Application(启动类):
代码语言:javascript复制@SpringBootApplication
public class KgblogApplication {
public static void main(String[] args) {
SpringApplication.run(KgblogApplication.class, args);
}
}
根据错误提示,没有UserDao这个bean.那么我们就在启动类上将该报扫描进去:
代码语言:javascript复制//@SpringBootApplication
@SpringBootApplication
@MapperScan(value = {"com.kaigejava.kgblog.dao"})
public class KgblogApplication {
public static void main(String[] args) {
SpringApplication.run(KgblogApplication.class, args);
}
}
解决方案三: