问题:

用Maven搭建spring、springmvc、mybatis时,运行报错:

org.springframework.beans.factory.BeanDefinitionStoreException: Could not resolve bean definition resource pattern
[classpath:spring/applicationContext-*.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/] cannot be resolved to URL because it does not exist

意思是说:
无法找到applicationContext-*.xml这个配置文件,因为这些文件不存在

原因:
在我的工程中,src/main/java下的mapper包中有mapper.java和mapper.xml文件,src/main/config目录有spring,mybatis,springmvc的配置文件

这两个路径下最终对应maven的运行路径时:

我们知道,maven在扫描java文件夹时,不会扫描其中的.xml文件,因为它默认是扫描java文件的,这样mapper.xml就会丢失而导致报错,所以我们会在pom文件中添加这样的配置:

<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resources>
</build>

上述配置的意思是:maven扫描src/main/java这个文件夹,并且要扫描所有.xml和.properties文件,这样一来可以解决maven扫描mapper.xml缺失的问题,但是由于修改了默认的resource目录,导致src/main/resources的所有文件都不能被扫描,也就出现了applicationContext文件不能被扫描的错误,所以应该配置两个:

<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
由于修改了默认的resource目录,导致src/main/resources的所有文件都不能被扫描,因此还要配多一个
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>

转自:https://blog.csdn.net/jeffleo/article/details/55271858

解决:Could not resolve bean definition resource pattern [/WEB-INF/classes/spring/applicationContext-*.xml]的更多相关文章

  1. eclipse报错:Could not resolve bean definition resource pattern [classpath:spring/applicationContext-*.xml]或者找不到

    1.把xml文件复制到WEB-INF下 2.路径改成 [/WEB-INF/spring/applicationContext-*.xml]

  2. 曹工说Spring Boot源码系列开讲了(1)-- Bean Definition到底是什么,附spring思维导图分享

    写在前面的话&&About me 网上写spring的文章多如牛毛,为什么还要写呢,因为,很简单,那是人家写的:网上都鼓励你不要造轮子,为什么你还要造呢,因为,那不是你造的. 我不是要 ...

  3. Error creating bean with name 'sqlSessionFactory' defined in class path resource [config/spring/applicationContext.xml]: Invocation of init method failed;

    我报的错: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSes ...

  4. spring applicationContext.xml 中bean配置

    如果采用set get方法配置bean,bean需要有set get 方法需要有无参构造函数,spring 在生成对象时候会调用get和set方法还有无参构造函数 如果采用constructor方法则 ...

  5. class path resource [spring/applicationContext.xml] cannot be opened because it does not exist

    1.查看路径有没有写错 2.编辑器认为你的文件不是 source folders(原文件),需要你手动将文件改过来

  6. Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/config/spring/applicationContext.xml]

    在搭建SpringMVC框架的时候遇到了这个问题 问题的原因: 就是没有找到applicatoincontext.xml这个文件, 因为idea自动生成的路径不正确 因此需要再web.xml里面, ( ...

  7. 曹工说Spring Boot源码(2)-- Bean Definition到底是什么,咱们对着接口,逐个方法讲解

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码系列开讲了(1)-- Bean Definition到底是什么,附spring思维导图分享 工程代码地址 思维导图地址 工程结构图: 正 ...

  8. 曹工说Spring Boot源码(4)-- 我是怎么自定义ApplicationContext,从json文件读取bean definition的?

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码系列开讲了(1)-- Bean Definition到底是什么,附spring思维导图分享 工程代码地址 思维导图地址 工程结构图: 大 ...

  9. 曹工说Spring Boot源码(3)-- 手动注册Bean Definition不比游戏好玩吗,我们来试一下

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码系列开讲了(1)-- Bean Definition到底是什么,附spring思维导图分享 工程代码地址 思维导图地址 工程结构图: 大 ...

随机推荐

  1. SPOJ GSS1 - Can you answer these queries I(线段树维护GSS)

    Can you answer these queries I SPOJ - GSS1 You are given a sequence A[1], A[2], -, A[N] . ( |A[i]| ≤ ...

  2. Liunx之django项目部署

    一.python web 项目部署 python django默认启动python3 manage.py runserver 0.0.0.0:8000这种方式调用wsgiref单机模块,性能较低,生产 ...

  3. vue后台_登录权限

    登录权限控制包含着这么几个方面的含义: 1)不同的权限对应不同的路由 2)侧边栏需要根据不同的权限,异步生成 登录:使用用户名和密码,登录成功后返回用户的token(防止XSS攻击),将此token存 ...

  4. 史上最详细的C语言和Python的选择排序算法

    未经同意,请勿转载!如有收货,请留一赞,不胜感激! 同时欢迎加入我们的qq交流群:326079727 话不多说上代码: C语言: //选择排序走起 //原理:吃透原理再去实现,选择排序也是类似于冒泡排 ...

  5. koa 项目中引入 mysql

    由于mysql模块的操作都是异步操作,每次操作的结果都是在回调函数中执行,现在有了async/await,就可以用同步的写法去操作数据库 Promise封装mysql模块 Promise封装 ./as ...

  6. shell中的for循环用法详解

    for i in “file1” “file2” “file3”for i in /boot/*for i in /etc/*.conffor i in $(seq -w 10) –>等宽的01 ...

  7. hTTP的URL编码

    使用jdk提供的类完成URL的编解码 public class UrlDemo { public static void main(String[] args) throws Exception { ...

  8. mfc移动文件夹

    SHFILEOPSTRUCT FileOp; ZeroMemory((void*)&FileOp,sizeof(SHFILEOPSTRUCT)); FileOp.fFlags = FOF_NO ...

  9. JAVA 基础编程练习题20 【程序 20 求前 20 项之和】

    20 [程序 20 求前 20 项之和] 题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前 20 项之和. 程序分析:请抓住分子与分母的变化规律. pac ...

  10. es6 是否包含字符串判断

    字符串查找类 接下来介绍一些可以通过 ES5 PolyFill的方法,但是现在 ES6 原生实现了 Method Param Return Description includes() 需要验证是否被 ...