Configuration problem: Failed to import bean definitions from URL location classpath:spring-mvc.xml

在这里插入图片描述

💗wei_shuo的个人主页

💫wei_shuo的学习社区

🌐Hello World !


org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:spring-mvc.xml]

配置问题:无法从 URL 位置导入 Bean 定义

排错思路:

  • 查看bean是否注入成功
<!--将所有业务类注入Spring,可以通过配置或者注解-->
<bean id="BookServiceImpl" class="com.wei.service.BookServiceImpl">
    <property name="bookMapper" ref="bookMapper"/>
</bean>
  • Junit单元测试,看代码是否能查询出来结果
import com.wei.pojo.Books;
import com.wei.service.BookServiceImpl;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MyTest {
    @Test
    public void test() {
        //解析applicationContext.xml文件,生成管理相应的Bean对象
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
        //getBean:参数即为Spring配置文件中的bean的id
        BookServiceImpl bookServiceImpl = (BookServiceImpl) context.getBean("BookServiceImpl");

        for (Books books : bookServiceImpl.queryAllBook()) {
            System.out.println(books);
        }
    }
}
  • 如果查询出结果,说明问题出现在Spring
  • SpringMVC整合的时候没有调用service层的bean
    • applicationContext.xml没有注入bean
    • web.xml中绑定配置文件,配置的是spring-mvc.xml,没有service的bean

web.xml

<param-value>classpath:applicationContext.xml</param-value>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <import resource="classpath:spring-dao.xml"/>
    <import resource="classpath:spring-service.xml"/>
    <import resource="classpath:spring-mvc.xml"/>
    
</beans>

🌼 结语:创作不易,如果觉得博主的文章赏心悦目,还请——点赞👍收藏⭐️评论📝冲冲冲🤞


在这里插入图片描述

  • 22
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 17
    评论
评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wei_shuo

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值