• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

SpringMVC 报错Could not open ServletContext resource

武飞扬头像
我们不敲代码,我们只是代码的搬运工
帮助2

在做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了。

学新通

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

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgbkahi
系列文章
更多 icon
同类精品
更多 icon
继续加载