使用maven分模块开发时,将项目分成三次dao(bean),service,web,其中dao层包含了bean和applicationContext,hibernate配置文件,service层依赖dao,也包含了spring配置文件(spring管理三层,所以都需要spring配置文件)。
首先配置号dao层,install发布到本地仓库,此时dao是jar格式,service引入dao.jar依赖解决依赖关系,但是service层配置spring文件时,无法找到spring容器内的dao对象,配置报错
<bean id="customerService" class="service.Impl.CustomerServiceImpl"> <property name="customerDao" ref="customerDao"></property> </bean>
此时只需导入dao层的配置文件即可
<import resource="applicationContext_dao.xml"></import> <bean id="customerService" class="service.Impl.CustomerServiceImpl"> <property name="customerDao" ref="customerDao"></property> </bean>