maven—分模块开发与设计

news2025/3/13 18:01:44

项目与模块下载

任务:

将springmvc_ssm这个ssm整合后的项目拆分成四个模块,如下图:

ssm_pojo拆分

新建模块

 从原始项目中拷贝实体类(User)到该模块

ssm_dao拆分

新建模块

从原始项目中拷贝相关内容到该模块

  • 数据层接口(UserDao)
  • 配置文件:3个

注意:分页插件在配置中与SqlSessionFactoryBean绑定,需要保留,如下:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <!--开启bean注解扫描-->
    <context:component-scan base-package="com.itheima"/>

    <!--加载properties文件-->
    <context:property-placeholder location="classpath*:jdbc.properties"/>

    <!--数据源-->
    <bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="url" value="${jdbc.url}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
    </bean>

    <!--整合mybatis到spring中-->
    <bean class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliasesPackage" value="com.itheima.domain"/>
        <!--分页插件-->
        <property name="plugins">
            <array>
                <bean class="com.github.pagehelper.PageInterceptor">
                    <property name="properties">
                        <props>
                            <prop key="helperDialect">mysql</prop>
                            <prop key="reasonable">true</prop>
                        </props>
                    </property>
                </bean>
            </array>
        </property>
    </bean>

    <!--映射扫描-->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.itheima.dao"/>
    </bean>

</beans>
  •  pom.xml:事先对ssm_pojo模块执行install指令,将其安装到本地仓库,再引入数据层相关坐标即可,删除springmvc相关坐标,具体依赖如下:
<!--导入资源文件pojo-->
        <dependency>
            <groupId>com.itheima</groupId>
            <artifactId>ssm_pojo</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>

        <!--spring环境-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.3.19</version>
        </dependency>

        <!--mybatis环境-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.6</version>
        </dependency>
        <!--mysql环境-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.28</version>
        </dependency>
        <!--spring整合jdbc-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>5.3.12</version>
        </dependency>
        <!--spring整合mybatis-->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>2.0.6</version>
        </dependency>
        <!--druid连接池-->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.22</version>
        </dependency>
        <!--分页插件坐标-->
        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper</artifactId>
            <version>5.1.6</version>
        </dependency>

ssm_service拆分

新建模块

从原始项目中拷贝相关内容到该模块

  • 业务层接口和实现类(UserService、UserServiceImpl)
  • 配置文件:applicationContext-service.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">

    <!--开启bean注解扫描-->
    <context:component-scan base-package="com.itheima"/>

    <!--开启注解式事务-->
    <tx:annotation-driven transaction-manager="txManager"/>

    <!--事务管理器-->
    <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"/>
    </bean>

</beans>
  • pom.xml
        <!--导入资源文件dao-->
        <dependency>
            <groupId>com.itheima</groupId>
            <artifactId>ssm_dao</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    
        <!--spring环境-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>5.3.12</version>
        </dependency>

        <!--junit单元测试-->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
        </dependency>

        <!--spring整合junit-->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>5.3.19</version>
        </dependency>
  •  修改单元测试引入的配置文件名称,又单个文件修改为多个:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath:applicationContext-service.xml","classpath:applicationContext-dao.xml"})
public class UserServiceTest {

ssm_controller拆分 

 新建模块(使用webapp模板)

从原始项目中拷贝相关内容到该模块

  • 表现层控制器类与相关设置类(UserController、异常相关。。。)
  • 配置文件:保留与表现层相关配置文件(spring-mvc.xml)、服务器相关配置文件(web.xml),如下:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <mvc:annotation-driven/>
    <context:component-scan base-package="com.itheima.controller"/>

</beans>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
         http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:applicationContext-*.xml</param-value>
  </context-param>

  <!--启动服务器时,通过监听器加载spring运行环境-->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <servlet>
    <servlet-name>DispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath*:spring-mvc.xml</param-value>
    </init-param>
  </servlet>
  <servlet-mapping>
    <servlet-name>DispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

</web-app>

注意:修改了web.xml中加载spring环境的配置文件名称,使用*通配符,加载所有applicationContext-开头的配置文件。

  • pom.xml:
    <dependency>
      <groupId>com.itheima</groupId>
      <artifactId>ssm_service</artifactId>
      <version>1.0-SNAPSHOT</version>
    </dependency>

    <!--springmvc环境-->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>5.3.19</version>
    </dependency>
    <!--jackson相关坐标3个-->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>2.9.0</version>
    </dependency>
    <!--<dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-core</artifactId>
        <version>2.9.0</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.9.0</version>
    </dependency>-->
    <!--servlet环境-->
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>4.0.1</version>
      <scope>provided</scope>
    </dependency>

分模块开发总结:

1、模块中仅包含当前模块对应的功能类与配置文件

2、spring核心配置文件根据模块功能不同进行独立制作

3、被依赖的模块要安装到本地仓库,其他模块才能使用其坐标。

4、web.xml需要加载所有的spring核心配置文件

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/103276.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

DEJA_VU3D - Cesium功能集 之 089-台风范围几何绘制

前言 编写这个专栏主要目的是对工作之中基于Cesium实现过的功能进行整合,有自己琢磨实现的,也有参考其他大神后整理实现的,初步算了算现在有差不多实现小130个左右的功能,后续也会不断的追加,所以暂时打算一周2-3更的样子来更新本专栏(尽可能把代码简洁一些)。博文内容…

学习IB带给了我什么?

在某些层面&#xff0c;IB课程类似于大家更加熟知的AP课程——它是一种让高中学生学习高级、严格课程的体系。然而&#xff0c;有两个主要区别。首先&#xff0c;IB项目在美国高中或者美国大学申请中的受欢迎程度远远低于AP课程&#xff08;个人感觉是这样子滴哈&#xff09;&a…

【复习笔记】嵌入式系统及其原理复习重点

嵌入式系统及其原理复习重点笔记 计算机的发展 第一代——电子管计算机&#xff08;1946—1954年&#xff09; 内 存 延迟线或磁芯外 存 纸带、卡片或磁带工作速度 几千&#xff5e;一万次&#xff0f;秒软 件 机器语言或汇编语言应 用 科学计算代表机型 ENIAC特 点 体积庞大…

【vue】简易封装echarts

将echarts封装成组件&#xff0c;达到只要调用方法&#xff0c;传入数据和相应的参数就能生成图表的效果&#xff0c;避免在项目中编写大量重复和累赘的echarts的配置代码&#xff0c;实现的思路如下&#xff1a; 接口返回的一般是json数据&#xff0c;所以首先要将json数据进…

【LVGL学习笔记】(四)PlatformIO + LVGL8.3配置

LVGL全程LittleVGL&#xff0c;是一个轻量化的&#xff0c;开源的&#xff0c;用于嵌入式GUI设计的图形库。并且配合LVGL模拟器&#xff0c;可以在电脑对界面进行编辑显示&#xff0c;测试通过后再移植进嵌入式设备中&#xff0c;实现高效的项目开发。 LVGL中文教程手册&#…

PicGo+GitHub搭建个人图床用于Markdown、HTML等图片引用

方便程度&#xff1a;★★★★☆ 配置难度&#xff1a;★★☆☆☆ 稳定性&#xff1a;★★★★★ 适用环境&#xff1a;Windows、Mac、Linux 需要工具&#xff1a;GitHub 账号、PicGo 客户端 隐私性&#xff1a;别人可以访问你的图片仓库 GitHub仓库设置 流程&#xff1…

vue后台系统管理项目-商城轮播图管理功能

商城轮播图管理功能 功能介绍&#xff1a; 1.轮播图列表分页功能&#xff1b; 2.轮播图添加功能&#xff1b; 3.轮播图编辑功能&#xff1b; 4.轮播图删除功能&#xff1b; 5.轮播图启用禁用功能&#xff1b; 6.轮播图获取排序号功能&#xff1b; 7.轮播图查看详情功能&#xf…

2.创建自己的Cesiunm地球隐藏控件

目录​​​​​​​ 一、创建地球 引入Cesium.JS和初始页面 修改初始页面 将项目通过tomcat发布 二、去除不需要的控件 一、创建地球 引入Cesium.JS和初始页面 创建一个名为my-cesium的文件夹&#xff0c;将下载好的Cesium中的Build文件夹和Apps中的HelloWorld.html复制到…

基于Android的地铁查询系统app-计算机毕业设计

项目介绍 本软件研究了一个Android平台的地铁查询软件实现方案,从数据库数据保存到地铁数据的提取&#xff0c;再到界面的友好展示,最后到一个成型软件的生成这样一个过程,研究了SQLite数据库在Android平台的应用以及在手机平台的展示等等。 系统提供了地铁线路、站点和换乘的…

3.Entity和CZML添加图形

目录 Entity创建盒子 创建view容器 配置Entity ​编辑CZML数据添加图形 CZML是什么 怎么加载CZML Entity创建盒子 创建view容器 <!DOCTYPE html> <html lang"en"><head><!-- Use correct character set. --><meta charset"ut…

精华推荐 |【深入浅出Sentinel原理及实战】「原理探索专题」完整剖析Alibaba微服务架构体系之轻量级高可用流量控制组件Sentinel(1)

Sentinel是什么&#xff1f;不要概念混淆啊&#xff01; 注意&#xff1a;本Sentinel与Redis服务Sentinel是两回事&#xff0c;压根不是一个概念&#xff0c;请大家不要混肴。 Alibaba的Sentinel Sentinel是由阿里巴巴中间件团队开发的开源项目&#xff0c;是一种面向分布式微…

Vuex的相关知识

「Vuex的相关知识」 ​ vuex是一种对vue 应用中多个组件的共享状态进行集中式的管理(读/写)&#xff1b; vuex的工作原理&#xff1a; https://segmentfault.com/a/1190000021717329 ​ vuex 核心概念和API&#xff1a;state、mutations、actions、getters、modules、向外暴…

green power 设备入网过程

目录 Green Power设备入网流程 单项green power commissioning过程 抓包实例 1. SINK发送Green Power:GP Proxy Commissioning Mode命令​编辑​编辑 2. GPD发送入网命令 3. Proxy和Sink发送Green Power:GP Commissioning Notification 4. …

通过 Request 请求获取真实 IP 地址以及对应省份城市

title: 通过 Request 请求获取真实 IP 地址以及对应省份城市和系统浏览器信息 date: 2022-12-16 16:20:26 tags: GeoIP2UserAgentUtils categories:开发技术及框架 cover: https://cover.png feature: false 1. 获取真实 IP 地址 1.1 代码 代码如下&#xff0c;这里的 Commo…

set、map使用及其细节

&#x1f9f8;&#x1f9f8;&#x1f9f8;各位大佬大家好&#xff0c;我是猪皮兄弟&#x1f9f8;&#x1f9f8;&#x1f9f8; 文章目录一、两个概念①关联式容器与序列式容器②键值对二、set、map①setset的两种遍历方式set的升降序排序set的eraseset的count②mapSGI-STL中键值…

ISCSLP论文介绍|利用BERT提高语种识别性能

本文介绍清华大学语音与音频技术实验室&#xff08;SATLab&#xff09;ISCSLP 2022录用论文。BERT-LID: Leveraging BERT to Improve Spoken Language Identification。这篇文章将BERT模型引入到语种识别领域。利用BERT模型的优越性&#xff0c;再结合下游不同的神经网络模型&a…

OFDM系统中基于dmrs导频的时间跟踪、频率跟踪算法

目录发射端模型假设接收端模型假设时延估计&#xff08;时间跟踪&#xff09;频偏估计&#xff08;频率跟踪&#xff09;在OFDM系统中&#xff0c;为了估计出信号传输遇到的时间偏移和频率偏移&#xff0c;可以采用导频进行估计。 发射端模型假设 我们假设如下模型&#xff1…

如何熟练掌握运用Delft3D建模、水动力模拟方法及在地表水环境影响评价中的实践技术

Delft3D是由荷兰Delft大学WL Delft Hydraulics开发的一套功能强大的软件包&#xff0c;主要应用于自由地表水环境。该软件具有灵活的框架&#xff0c;能够模拟二维和三维的水流、波浪、水质、生态、泥沙输移及床底地貌&#xff0c;以及各个过程之间的相互作用。它是国际上最为先…

使用 C# Graphics 绘图来绘制一个足球

背景 2022卡塔尔世界杯是足球爱好者的狂欢&#xff0c;这与我毫无关系&#xff0c;作为一个缺乏运动的人&#xff0c;还是不要去看人家玩命的运动了。虽然不看球&#xff0c;不过这波热度的持续冲击&#xff0c;还是让我在朋友圈刷到了结局 ———— 球王梅西如愿以偿捧得金杯…

Bootstrap5 下拉菜单

下拉菜单可以是单选下拉菜单&#xff0c;也可以是多选的下拉菜单。 单选下拉菜单&#xff1a; 多选下拉菜单&#xff1a; 在 Bootstrap5 中下拉菜单 <select> 元素可以使用 .form-select 类来渲染 : 实例 <select class"form-select"> <option>…