Error creating bean with name 'userServiceImpl'Injection of autowired 分布式新搭建项目无法自动装配 creating bean
错误:Error creating bean with name 'userServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.acid.cat.dao.UserDao com.acid.cat.service.impl.UserServiceImpl.userDao; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.acid.cat.dao.UserDao] 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)}
翻译
报错:创建名为'userServiceImpl'的bean时出错:注入自动连接的依赖项失败; 嵌套异常是org.springframework.beans.factory.BeanCreationException:无法自动装配字段
改配置之前是可以正常运行的 这种报错提示很明确问题在那个类,但范围比较大,根据这个类错误可能性排查一下,如果能记录能报错具体位置就更好了。
- 备注 因为是扫描问题所以
- :试过改spring scan 包扫描路径 <context:component-scan base-package="com.name.*" >
- :查看UserServiceImpl类@Autowired
- :查看spring.xml ,springmvc.xml,web.xml 配置
- :查看 tomcat 文件
- :还要注意大小写,字母,单词不能错,没字幕大小写没对上那就是个坑
最后发现是之前少了这个配置造成serviceimpl无法自动装配 ,
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
<property name="configLocation" value="classpath:mybatis/config.xml" />
<property name="dataSource" ref="dataSource" />
<property name="mapperLocations" >
<list>
<value>classpath*:mybatis/mapper-*.xml</value>
</list>
</property>
</bean>
补充配置后
运行成功后
:备忘加强了解spring配置使用