解决:Could not resolve bean definition resource pattern [/WEB-INF/classes/spring/applicationContext-*.xml]
问题:
用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]的更多相关文章
- eclipse报错:Could not resolve bean definition resource pattern [classpath:spring/applicationContext-*.xml]或者找不到
1.把xml文件复制到WEB-INF下 2.路径改成 [/WEB-INF/spring/applicationContext-*.xml]
- 曹工说Spring Boot源码系列开讲了(1)-- Bean Definition到底是什么,附spring思维导图分享
写在前面的话&&About me 网上写spring的文章多如牛毛,为什么还要写呢,因为,很简单,那是人家写的:网上都鼓励你不要造轮子,为什么你还要造呢,因为,那不是你造的. 我不是要 ...
- 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 ...
- spring applicationContext.xml 中bean配置
如果采用set get方法配置bean,bean需要有set get 方法需要有无参构造函数,spring 在生成对象时候会调用get和set方法还有无参构造函数 如果采用constructor方法则 ...
- class path resource [spring/applicationContext.xml] cannot be opened because it does not exist
1.查看路径有没有写错 2.编辑器认为你的文件不是 source folders(原文件),需要你手动将文件改过来
- Caused by: java.io.FileNotFoundException: Could not open ServletContext resource [/config/spring/applicationContext.xml]
在搭建SpringMVC框架的时候遇到了这个问题 问题的原因: 就是没有找到applicatoincontext.xml这个文件, 因为idea自动生成的路径不正确 因此需要再web.xml里面, ( ...
- 曹工说Spring Boot源码(2)-- Bean Definition到底是什么,咱们对着接口,逐个方法讲解
写在前面的话 相关背景及资源: 曹工说Spring Boot源码系列开讲了(1)-- Bean Definition到底是什么,附spring思维导图分享 工程代码地址 思维导图地址 工程结构图: 正 ...
- 曹工说Spring Boot源码(4)-- 我是怎么自定义ApplicationContext,从json文件读取bean definition的?
写在前面的话 相关背景及资源: 曹工说Spring Boot源码系列开讲了(1)-- Bean Definition到底是什么,附spring思维导图分享 工程代码地址 思维导图地址 工程结构图: 大 ...
- 曹工说Spring Boot源码(3)-- 手动注册Bean Definition不比游戏好玩吗,我们来试一下
写在前面的话 相关背景及资源: 曹工说Spring Boot源码系列开讲了(1)-- Bean Definition到底是什么,附spring思维导图分享 工程代码地址 思维导图地址 工程结构图: 大 ...
随机推荐
- [Luogu] 遥远的国度
https://www.luogu.org/problemnew/show/P3979 3种情况 x=root,很显然此时应当查询整棵树 lca(root,x)!=x ,此时直接查询x的子树即可,与换 ...
- 基础数据类型-字符串str
什么是字符串? 单引号,双引号,三引号包裹的文本 在我们的代码中换行区别 单/双引号:‘a’\ 'b' 三引号:"""a b""" 索引 s ...
- 二十、网络ifconfig 、ip 、netstat、ss之二
ip 网络层协议 ip地址 点分十进制分为4段,范围 0-255 ip分类 A 占据1段,最左侧一段第一位固定为0 0 000 0000 - 0 111 1111 0 - 127:其中0为网络,12 ...
- js 数组 删除第一个和最后一个
.shift(); 删除第一个 .pop(); 删除最后一个
- spring boot + swagger2
spring boot集成swagger2: swagger2是一个基于restful的开源设计,构建,文档,访问的开源工具集.开发中它的在线可视化文档功能,可以动态生成文档,简化前后对接工作 ...
- struts2方法无法映射问题:There is no Action mapped for namespace [/] and action name [m_hi] associated with context path []
使用struts的都知道,下面使用通配符定义的方式很常见,并且使用也很方便: <action name="Crud_*" class="example.Crud&q ...
- Hadoop 3.2.1 win10 64位系统 vs2015 编译
Hadoop 3.2.1 win10 64位系统 vs2015 编译 1 环境配置 1.1 JDK下载安装 1.1.1 下载 JDK 1.8 (jdk1.8.0 ...
- JAVA - IO - IO的类型(AIO, BIO, NIO)
IO的方式通常分为几种,同步阻塞的BIO.同步非阻塞的NIO.异步非阻塞的AIO. 一.BIO 在JDK1.4出来之前,我们建立网络连接的时候采用BIO模式,需要先在服务端启动一个ServerSock ...
- elasticsearch java动态设置mapping并指定分词器
//创建索引 client.admin().indices().prepareCreate("twitter").execute().actionGet(); //配置mappin ...
- Golang的文件处理方式-常见的读写
在 Golang 语言中,文件使用指向 os.File 类型的指针来表示的,也叫做文件句柄.注意,标准输入 os.Stdin 和标准输出 os.Stdout ,他们的类型都是 *os.File 哟.在 ...