问题:

用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. Codeforces Round #521 (Div.3)题解

    A过水,不讲 题解 CF1077B [Disturbed People] 这题就是个显而易见的贪心可是我考场上差点没想出来 显然把一户被打扰的人家的右边人家的灯关掉肯定比把左边的灯关掉 从左到右扫一遍 ...

  2. Liunx之nginx配置

    一.nginx安装 卸载yum安装的ngjnx yum remove nginx -y 编译安装nginx步骤 编译安装nginx的步骤 1.解决软件依赖 yum install gcc patch ...

  3. 数据分析之matplotlib使用

    绘制折线图 参数详情 from matplotlib import pyplot as plt # 设置图片大小,dpi图片放大缩小时可以让其更清晰 plt.figure(figsize=(20,8) ...

  4. 两大主流开源分布式存储的对比:GlusterFS vs. Ceph

    两大主流开源分布式存储的对比:GlusterFS vs. Ceph 存储世界最近发生了很大变化.十年前,光纤通道SAN管理器是企业存储的绝对标准,但现在的存储必须足够敏捷,才能适应在新的基础架构即服务 ...

  5. debian、ubuntu安装metasploit通用方法

    网上有很多方法让去github上下载安装,这方法的确可以但是特别慢,更新也特别慢,这里写下比较快的方法 1.添加kali源 vim /etc/apt/sources.list 在原有源的基础上添加国内 ...

  6. DataTable 转换为List

           注意table 列的参数类型,若不为string 需要详细声明 如 typeof(Int32)          public static IList<T> Convert ...

  7. 【Java/MySql】使用JDBC访问MySql数据库的Maven工程

    下载链接:https://files.cnblogs.com/files/xiandedanteng/FindNotnullColumns20191102-1.rar pom.xml里写: <p ...

  8. UNIX 历史问题 分布式系统的Thundering Herd效应 惊群效应

    https://uwsgi-docs.readthedocs.io/en/latest/articles/SerializingAccept.html One of the historical pr ...

  9. UML期末复习题——2.9:UML Deployment Diagram

    附加题:部署图 重要概念: 1. 部署图 部署图表示的是,如何将具体的软件制品(例如可执行文件)分配到计算节点(具有处理服务的某种事物)上.部署图表示了软件元素在物理架构上的部署,以及物理元素之间的通 ...

  10. natively 在本地机器

    ​For JavaScript-based projects, it makes sense to have a command line task runner that executes Java ...