拆分applicationContext.xml为applicationContext-dao.xml,applicationContext-service和applicationContext-transaction时报错
报错如下:
Could not autowire field: private service.SongService controller.SongController.songService; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘songServiceImpl’: Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private mapper.SongMapper service.impl.SongServiceImpl.songMapper; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [mapper.SongMapper] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency.
解决方法:
分解applicationContext的时候需要更改web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/classes/spring/applicationContext-*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>