ssm关于找不到mapper.xml文件的问题,pom.xml配置资源文件的问题

3 篇文章 0 订阅

其实不光是mapper.xml文件,还有一些其他的资源会加载失败,我自己尝试了n多办法,但都失败了,结合了网上CSDN和博客园里面多篇文章的内容,才算是搞定了这个问题,但是看过的文章实在是忘记都有哪些了,就不贴出来了,在这里向技术大佬致敬。

 

一般我的xml文件和properties文件(例:log4j.properties,jdbc.properties,spring-mvc.xml)都是放在config目录里面,和src目录是平级的,

而在我运行时,经常会遇到mybatis的mapper.xml文件加载失败的情况,而log4j.properties更是家常便饭。

 

结合多篇文章的结果得出的解决办法就是在pom.xml文件里面配置资源文件的位置,

这个解决只能用于maven项目,不过现在不用maven的web项目已经很少了吧,毕竟手动导包挺麻烦的,pom.xml不香吗。

注意,要配置每个xml文件和properties的位置,

因为在pom.xml里面配置过资源文件后,原本项目默认的资源文件路径配置可能失效,

比如 src/main/recources

 

 

这里贴出我的pom.xml的相关部分代码

 

<!--                     加载配置资源文件                     -->
<resources>
    <!--            Config             -->
    <resource>
        <directory>config</directory>
        <includes>
            <include>spring-mvc.xml</include>

            <include>applicationContext-DB.xml</include>
            <include>applicationContext-User.xml</include>

            <include>ApplicationContext/ac-DataSource.xml</include>
            <include>ApplicationContext/ac-Transaction.xml</include>
            <include>ApplicationContext/ac-SqlSessionsFactoryDB.xml</include>
            <include>ApplicationContext/ac-SqlSessionsFactoryUser.xml</include>
        </includes>
        <filtering>true</filtering>
    </resource>
    <!--            Config             -->

    <!--           Properties and Mapper          -->
    <resource>
        <directory>config</directory>
        <includes>
            <include>Properties/jdbc.properties</include>
            <include>Properties/log4j.properties</include>

            <!--               Maper               -->
            <include>Mapper/User/AdminMapper.xml</include>
            <include>Mapper/User/StudentMapper.xml</include>
            <include>Mapper/User/TeacherMapper.xml</include>

            <include>Mapper/DB/DBMapper.xml</include>
            <!--               Maper               -->
        </includes>
        <filtering>false</filtering>
    </resource>
    <!--           Properties and Mapper          -->

</resources>
<!--                     加载配置资源文件                     -->

<resources></resources>标签是要放到<build></build>标签内的

关于<filtering></filtering>的取值是true和false,是否开启过滤,

可以选择性的搭配<properties></properties>标签配合使用,具体标准规范请参照相关的文档或技术文章。

<directory>和<includes>结合来锁定获取一个资源文件,

<directory>是获取目录,<includes>是映射路径

 

资源文件将会映射到 项目\WEB-INF\classes目录下

具体映射关系如下

<!-- 这个配置将会把项目里的config/Properties/jdbc.properties文件映射到
项目/WEB-INF/classes/Properties/jdbc.properties  -->

<resource>
        <directory>config</directory>
        <includes>
            <include>Properties/jdbc.properties</include>
        </includes>
</resource>

<!-- 这个配置将会项目里的config/Properties/jdbc.properties文件映射到
项目/WEB-INF/classes/jdbc.properties -->

<resource>
        <directory>config/Properties</directory>
        <includes>
            <include>jdbc.properties</include>
        </includes>
</resource>

具体映射规则,将pom.xml里的配置和 tomcat/webapps/classes目录里的对比一下就了解了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
源说明】 1、该源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考料学习借鉴。 3、本源作为“参考料”如果需要实现其他功能,需要能看懂代码,并且热爱钻研,自行调试。 基于SSM+Mysql实现的CRM信息管理系统源码+数据库+项目说明.zip # SSM项目实战:Crm信息管理系统 ## 1. 系统的功能和简介 * 一个数据管理系统,基于SSM框架进行开发,利用Maven构建和打包。 + 有登录模块。 + 对数据的管理功能(CRUD)。 + 分页的显示。 * > 本项目源于TyCoding开源项目 [SSM](https://github.com/TyCoding/ssm)。 > > 项目中的所有实现我都通过自己学习后进行编写。 * #### 改进地方: + 改进了分页的bug。 + 添加了拦截器进行权限认证。 + 添加了数据响应页面倒计时回主页。 + 添加了显示用户名。 * #### 适用人群: + 用于熟悉SSM框架的开发人员。 + 学习数据的分页。 ## 2. 系统的环境搭建 * 本系统通过Maven来进行环境的搭建,Maven的依赖,我已经打包好了,在根目录的tree.txt目录下,也可以通过pom文件来进行查看。 * 文件的目录如下: <img src="/img/src.png" > * main项目下是项目的主要实现代码,resources用于存放配置xml。 * test目录是用于存放测试的Java代码,本例中主要用于测试mapper和service编写是否正确。 * mysql文件已经放在目录下。 * 本系统的搭建环境: * Java:1.8.0.191 * mysql:8.0.13 * Maven:3.6.0 * Spring:4.2.4 * Mybatis:3.2.8 ## 3.注意事项 * 注意mysql连接驱动和mysql的版本,当初我在搭建的时候因为我的Mysql和原作者的Mysql版本不一致,一直无法连接到数据库,抛了异常解决了很久。 * 注意mysql8.0之后jdbc的驱动修改了,在url中需要配置时区: * ```mysql jdbc.driver=com.mysql.cj.jdbc.Driverjdbc. url=jdbc:mysql://localhost:3306/mycrm? characterEncoding=utf-8&serverTimezone=GMT%2B8&useSSL=false jdbc.user=root jdbc.password=root ``` * 要注意通过Maven搭建项目的时候要注意包冲突。 ## 4.项目展示 * 首页:username为admin,密码为admin。 * <img src="/img/首页.png" /> * 主页: * <img src="/img/主页.png" /> * 添加: * <img src="/img/添加.png" /> ## 5.jsp页面说明 * 前端页面: * <img src="/img/前端页面.png" /> * index为主页,info用于跳转信息页面,list为页面信息显示,save为添加用户的页面,page为导航栏。 * ## 6.分页功能 * 在以前的时候,我们通常是怎么分页的呢? * 首先通过mysql的limit来进行分页 ```mysql select * from A limit 1,10; ``` * limit表示从第几条到第几条。 * 同时我们需要在前端传入,第几页,一页显示多少条。 * 然后我们通过计算: * ```Java 通过前端传入的条数,我们需要先对数据库所有符合条件的数据进行查,除以条数,得出总页数。 然后我们通过传入的(页数-1)*条数得出数据是从第几条开始到第几条结束。 再通过一个对象封装起来,传入前端。 ``` * 使用了PageHelper之后,我们就不需要再如此繁琐的进行分页了。 * ```Java 使用PageHelper.startPage(第几页,每页显示多少条);就可以在这段代码之后的下一个查询的数据就会自动分页。 ``` * 同样PageHeler里面有一个PageInfo的类可以对数据进行封装,封装的内容和程序中用于封装的p
1、整合准备 整合内容: 整合架构:SpringSpringMVC以及MyBatis的整合。 数据库:MySQL 连接池:Druid(阿里巴巴研发) 整合工具: 整合工具为:Eclipse Jar管理工具:Maven 项目类型为:Maven Pproject 2、SSM整合 2.1、导入整合相关的jar包(Maven) pom.xml文件 <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>com.woo0nise</groupId> <artifactId>woo0nise-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>SSM</groupId> <artifactId>SSM</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <dependencies> <!-- MySql --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> </dependency> <!-- 连接池 --> <dependency> <groupId>com.alibaba</groupId> <artifactId>druid</artifactId> </dependency> <!-- Spring --> <!-- spring核心包 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> </dependency> <!-- Spring对JDBC的封装 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> </dependency> <!-- 关系型数据库整合时需配置 如hibernate jpa等 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> </dependency> <!-- Spring MVC核心 --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> </dependency> <!-- Jackson Json处理工具包(非必须) --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <!-- 单元测试 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <scope>test</scope> </dependency> <!-- 日志处理(非必须) --> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> </dependency> <!-- Mybatis --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> </dependency> <!-- mybatis的整合包 --> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis-spring</artifactId> </dependency> <!-- mybatis分页插件(非必须) --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> </dependency> <dependency> <groupId>com.github.miemiedev</groupId> <artifactId>mybatis-paginator</artifactId> </dependency> <!-- JSP相关 --> <dependency> <groupId>jstl</groupId> <artifactId>jstl</artifactId> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>servlet-api</artifactId> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>jsp-api</artifactId> <scope>provided</scope> </dependency> </dependencies> <!-- 如果不添加此节点mybatismapper.xml文件都会被漏掉。 --> <build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> </resources> </build> </project>

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值