SpringMVC 报错Could not open ServletContext resource

在做SpringMVC项目时,启动maven时遇到了以下报错,看了许多博文都没解决,以下分享我的改错经历

org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [com.itheima.config.SpringConfig]; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/jdbc.properties]

该报错的核心是Could not open ServletContext resource,表示无法打开ServletContext资源,经过查阅相关博文发现,导致该错误是因为SpringConfig配置类中@PropertySource的配置写错,正确写法是@PropertySource("classpath:jdbc.properties")。

还有一个报错就是

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'bookServiceImpl': Unsatisfied dependency expressed through field 'bookDao'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.itheima.dao.BookDao' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

该报错的主要意思是:bookServiceImpl bean创造错误,不能通过bookDao满足依赖表达,意思就是说bean加载失败,不能正确识别BookDao接口的注解,经过检查发现,是MyBatisConfig中mapperScannerConfigurer()方法缺少了@Bean注解。

在测试时,还遇到Could not load CacheAwareContextLoaderDelegate错误,经过查看博文发现spring-webmvc与spring-test版本要一致才行,被各种版本搞emo了。

经过本次改错的经历,我认识到了尽管报错一样,但真正的错误很可能不一样,要解决错误还要结合报错语句给出的提示,不能只是通过博文大概地去比对别人错误的解决办法。

  • 13
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值