当前位置: 代码迷 >> 综合 >> idea上使用maven分模块开发时解决spring注入失败问题java.lang.IllegalStateException: Failed to load ApplicationContext
  详细解决方案

idea上使用maven分模块开发时解决spring注入失败问题java.lang.IllegalStateException: Failed to load ApplicationContext

热度:80   发布时间:2023-11-23 14:38:55.0

使用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>