我的配置文件是在web.xml里面配置的 但是要用到spring的注入,有一次我拿了半天都拿不到spring注入的值,原来问题出在这里
得到spring的上下文
WebApplicationContext context1 = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
musicListService = (MusicListService) context1.getBean("musicListService");
songService = (SongService) context1.getBean("songService");
spring的注入
<bean id="songService" class="com.chinaGPS.song.service.impl.SongServiceImpl">
<property name="songDao" ref="songDao" />
<property name="singerDao" ref="singerDao" />
<property name="musicListShipDao" ref="musicListShipDao" />
</bean>
得到spring的上下文
WebApplicationContext context1 = WebApplicationContextUtils.getRequiredWebApplicationContext(context);
musicListService = (MusicListService) context1.getBean("musicListService");
songService = (SongService) context1.getBean("songService");
spring的注入
<bean id="songService" class="com.chinaGPS.song.service.impl.SongServiceImpl">
<property name="songDao" ref="songDao" />
<property name="singerDao" ref="singerDao" />
<property name="musicListShipDao" ref="musicListShipDao" />
</bean>
转载于:https://blog.51cto.com/hzywy/764557