SSM 項目從搭建爬坑到 CentOS 服務器部署 - 速查手冊
提示:
(1)CSDN 博客左邊有操作工具條上有文章目錄
(2)SSM 指 Spring,Spring MVC,MyBatis
Maven 的 pom.xml 配置合集
提示: 如果想查看當前最新版本,可以拷貝 xml 注解中的鏈接
基礎配置:
fastjson 1.2.54
spring-webmvc 5.1.4
spring-jdbc 5.1.4
mybatis 3.4.6
mybatis-spring 1.3.2
mysql-connector-java 8.0.13
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.54</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>5.1.4.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
其他擴展:
javax.servlet-api 4.0.1
commons-email 1.5
commons-fileupload 1.4
druid 1.1.12
junit 4.11
<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-email -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-email</artifactId>
<version>1.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
SSM 項目搭建
(1)按照博客詳細操作(含查詢實例):
(2)使用我的 Github 模板(含查詢實例):
- 打開 IDEA 創建項目頁面,如果有項目,點擊 File > Close Project
- 點擊 Check out from Version Control > Git
- 輸入 URL:https://github.com/xpwi/SSMTemplate.git
- 輸入 Directory(本地存放位置)
- 點擊 Clone
- 右下角 Enable Auto-Import
- 刪除版本控制 Settings > Version Control > 選中 > 點擊 --
- 配置 Tomcat,參考:創建 Maven Web 項目 + Tomcat 及目錄結構配置
CentOS 雲服務器環境搭建
(1)CentOS 雲服務器從購買到 JDK,Tomcat 及 MySQL 安裝及環境配置
(2)CentOS 雲服務器安裝 MySQL 8.0 及使用(所有的坑我走了一遍)
CentOS 雲服務器上部署 SSM 項目
(1)數據庫復制(建議使用 Navicat 12 可以直接連接),如果是在本機的數據庫需要連接服務器的數據庫進行同樣的搭建,轉出 SQL,在服務器新建數據庫,運行 SQL
(2)將 resources 中 jdbc.url 中的 localhost 改成服務器公網 ip
(3)將項目打包成 war 的形式,拷貝到 Tomcat 根目錄/webapps 目錄下
提示:
- war 不需要解壓,Tomcat 在運行時會自動檢測,自動解壓。Tomcat 運行的時候部署 war 時不能刪除 war 包,會同時刪除。
- 如果不想要 war 包,可以先關閉 Tomcat,再拷貝進去,手動解壓
- war 的名稱可以修改,但是在訪問的時候要用新改名稱的作為路徑
(4)訪問路徑(自動匹配 index.html 的方式):
http://公網ip:8080/war包解壓后的目錄名/