closeclosecloseclosecloseclosecloseclose
No qualifying bean of type 'com.thbd.netmaster.service.IUserInfoService' available: expected at least 1 bean which qualifies as autowire candidate.
IUserInfoService Spring没有注入,是不是Spring的xml文件没有配置或者类里忘记标@Service注释了
1、查找service.IUserInfoService上是否有@Service注解。
2、看看配置文件扫包的命名空间是否正确 (com.thbd.netmaster)。
由于:org.springframework.beans.factory.NoSuchBeanDefinitionException:没有可用的bean类型'com.thbd.netmaster.service.IUserInfoService'可用:预计至少有1个bean有资格作为autowire候选者。
没有配置注解,重新核对一遍吧!!!!
配置有问题,依赖注入出错,你可以尝试使用注解注入,比如在
@Service
public class UserServiceImpl {
@Autowired
private UserDaoMyBatis userDao;
}
可以看看Service接口和实现类(或者Service类)的注解吗?应该是注解没有写对
1、查找service.IUserInfoService上是否有@Service注解。
2、看看配置文件扫包的命名空间是否正确
NoSuchBeanDefinitionException:这个异常一般是因为需要注入的Bean未定义。你不能注入可继承的具体类。由于你的服务实现了接口,因此Sping创建了基于JDK接口的代理,即代理实现IUserInfoService接口并且委托给IUserInfoService。因此,Spring管理的bean不是IUserInfoService,而是UserService接口。
有两种方法解决:
1、最简单的方法是将您的依赖关系从IUserInfoService更改为IUserInfoService接口。
2、让Spring使用基于CGLIB类的代理,而不是基于JDK接口的代理。
链接上面回答,关于JDK代理和CGLIB代理可以参考这篇文章[《基于JDK动态代理和CGLIB动态代理的实现Spring注解管理事务(@Trasactional)到底有什么区别
beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userInfoController': Unsatisfied dependency expressed through field 'iUserInfoService'
这里可以看
1、@service注解有标注吗
2、spring配置文件里有开启注解扫描吗,开启了的话有扫到这个包吗
感谢大家回复,注解,xml配置,web xml context & 监听都有配置