今天在做项目的是时候启动一直报错:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'codeManager': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.igaming.business.mapper.ReddemCodeMapper com.igaming.gm.manager.CodeManager.reddemCodeMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [com.igaming.business.mapper.ReddemCodeMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
最后发现原因如下:
使用spring依赖注入,有严格的要求,必须要先有对象了,才能依赖注入。
因为在这个项目中,项目框架结构是直接拷贝的以前的项目框架,然后我在做的时候新加了包:


而且以前的项目,在spring配置文件写的是
com.igaming.gm.manager

还有就是项目中是不允许出现如下情况出现的:

今天启动项目发现又报这个错误,最后发现是@Service的包导错了,导成阿里巴巴的了。所以启动一直报错。
正确的应该是:
import org.springframework.stereotype.Service;