中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

springboot+idea+maven多模塊項目搭建的方法

發布時間:2020-08-13 16:00:33 來源:億速云 閱讀:1439 作者:小新 欄目:開發技術

這篇文章給大家分享的是有關springboot+idea+maven多模塊項目搭建的方法的內容。小編覺得挺實用的,因此分享給大家做個參考。一起跟隨小編過來看看吧。

創建之前項目之前 記得改一下 maven  提高下載Pom速度 

springboot+idea+maven多模塊項目搭建的方法

 記得 setting 中要改 maven  改成 阿里云的。具體方法 網上查第一步 搭建parents 項目,為maven項目 ,不為springboot 項目 記得修改groupId 

springboot+idea+maven多模塊項目搭建的方法  

第二步 搭建多個子模塊, honor-dao   honor-manager   honor-common記得創建 honor-manager 的時候 要把他的gruopId 改成com.honor.manager

springboot+idea+maven多模塊項目搭建的方法springboot+idea+maven多模塊項目搭建的方法

這里爆紅的原因是 因為 我做到后面然后忘記截屏了,返回來做。實際我已經創建了 ,所以這個步驟是對的。按照這個做法,創建 honor-dao   honor-manager   honor-common,記得創建 honor-manager 的時候 要把他的gruopId 改成com.honor.manager

springboot+idea+maven多模塊項目搭建的方法

第三步  在 honor-manager 下分別創建 honor-manager-fc(maven)  honor-manager-user(maven) honor-manager-boot (springboot,記得要使用springboot創建)創建時候 有兩個坑 第一個是 父級  別選錯 。他一般會默認 選第一級別,就是 honor  但是我們要繼承的是 honor-manager第二個是路徑 別寫錯

springboot+idea+maven多模塊項目搭建的方法springboot+idea+maven多模塊項目搭建的方法

第四步 開始對各大 Pom 進行整合  dao  中一般需要引入 common  ,common 一般不需要引 其他模塊,然后呢 manager 中要同時引入dao  和 common第一個是  honor  父級的 pom 

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<project xmlns="http://maven.apache.org/POM/4.0.0"
 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>
 <groupId>com.honor</groupId>
 <artifactId>phone</artifactId>
 <packaging>pom</packaging>
 <version>1.0-SNAPSHOT</version>
 <modules>
 <module>honor-dao</module>
 <module>honor-common</module>
 <module>honor-manager</module>
 </modules>
 <parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>2.1.7.RELEASE</version>
 <relativePath/> <!-- lookup parent from repository -->
 </parent>
 <properties>
 <honor-common>1.0-SNAPSHOT</honor-common>
 <honor-dao>1.0-SNAPSHOT</honor-dao>
 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
 <java.version>1.8</java.version>
 <skipTests>true</skipTests>
 <hutool.version>4.5.7</hutool.version>
 <swagger2.version>2.7.0</swagger2.version>
 <mybatis-generator.version>1.3.7</mybatis-generator.version>
 <mybatis.version>3.4.6</mybatis.version>
 <postgresql.version>42.2.12</postgresql.version>
 <spring-data-commons.version>2.1.5.RELEASE</spring-data-commons.version>
 <jjwt.version>0.9.0</jjwt.version>
 <aliyun-oss.version>2.5.0</aliyun-oss.version>
 <gson.version>2.8.5</gson.version>
 <log4j2.version>2.13.3</log4j2.version>
 <mybatis-plus.version>3.1.0</mybatis-plus.version>
 <activiti.version>6.0.0</activiti.version>
 <poi.version>4.1.2</poi.version>
 </properties>
 <dependencies>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-web</artifactId>
 <exclusions><!-- 去掉默認配置 -->
 <!--<exclusion>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-tomcat</artifactId>
 </exclusion>-->
 <exclusion>
 <groupId>org.hibernate.validator</groupId>
 <artifactId>hibernate-validator</artifactId>
 </exclusion>
 <exclusion>
 <groupId>ch.qos.logback</groupId>
 <artifactId>logback-classic</artifactId>
 </exclusion>
 <exclusion>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-logging</artifactId>
 </exclusion>
 </exclusions>
 </dependency>
 <!--<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-data-jpa</artifactId>
 </dependency>-->
 <!-- 移除Tomcat之后會報錯,加入下面的依賴,使用外部容器 -->
 <!--<dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-tomcat</artifactId>
 <scope>provided</scope>
 </dependency>-->
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-actuator</artifactId>
 </dependency>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-aop</artifactId>
 </dependency>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-test</artifactId>
 <scope>test</scope>
 </dependency>
 <dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-slf4j-impl</artifactId>
 <version>${log4j2.version}</version>
 <scope>compile</scope>
 </dependency>
 <dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-core</artifactId>
 <version>${log4j2.version}</version>
 <scope>compile</scope>
 </dependency>
 <dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-jul</artifactId>
 <version>${log4j2.version}</version>
 <scope>compile</scope>
 </dependency>
 <dependency>
 <groupId>org.apache.logging.log4j</groupId>
 <artifactId>log4j-api</artifactId>
 <version>${log4j2.version}</version>
 <scope>compile</scope>
 </dependency>
 <dependency>
 <groupId>javax.servlet</groupId>
 <artifactId>javax.servlet-api</artifactId>
 <version>3.1.0</version>
 <scope>provided</scope>
 </dependency>
 </dependencies>
 <dependencyManagement>
 <dependencies>
 <dependency>
 <groupId>org.junit.jupiter</groupId>
 <artifactId>junit-jupiter-api</artifactId>
 <version>5.5.0</version>
 <scope>test</scope>
 </dependency>
 <dependency>
 <groupId>com.honor</groupId>
 <artifactId>honor-common</artifactId>
 <version>${honor-common}</version>
 </dependency>
 <dependency>
 <groupId>com.honor</groupId>
 <artifactId>honor-dao</artifactId>
 <version>${honor-dao}</version>
 </dependency>
 <!--阿里巴巴連接池-->
 <dependency>
 <groupId>com.alibaba</groupId>
 <artifactId>druid-spring-boot-starter</artifactId>
 <version>1.1.20</version>
 </dependency>
 <!--Swagger-UI API文檔生產工具-->
 <dependency>
 <groupId>io.springfox</groupId>
 <artifactId>springfox-swagger2</artifactId>
 <version>${swagger2.version}</version>
 </dependency>
 <dependency>
 <groupId>io.springfox</groupId>
 <artifactId>springfox-swagger-ui</artifactId>
 <version>${swagger2.version}</version>
 </dependency>
 <!-- MyBatis-->
 <!--<dependency>
 <groupId>org.mybatis</groupId>
 <artifactId>mybatis</artifactId>
 <version>${mybatis.version}</version>
 </dependency>-->
 <!-- mybatis plus -->
 <dependency>
 <groupId>com.baomidou</groupId>
 <artifactId>mybatis-plus-boot-starter</artifactId>
 <version>${mybatis-plus.version}</version>
 </dependency>
 <dependency>
 <groupId>com.baomidou</groupId>
 <artifactId>mybatis-plus-generator</artifactId>
 <version>${mybatis-plus.version}</version>
 </dependency>
 <!--mysql-->
 <dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <scope>runtime</scope>
 <version>8.0.13</version>
 </dependency>
 <!--SpringData工具包-->
 <dependency>
 <groupId>org.springframework.data</groupId>
 <artifactId>spring-data-commons</artifactId>
 <version>${spring-data-commons.version}</version>
 </dependency>
 <!--JWT(Json Web Token)登錄支持-->
 <dependency>
 <groupId>io.jsonwebtoken</groupId>
 <artifactId>jjwt</artifactId>
 <version>${jjwt.version}</version>
 </dependency>
 <!--Google的JSON解析工具-->
 <dependency>
 <groupId>com.google.code.gson</groupId>
 <artifactId>gson</artifactId>
 <version>${gson.version}</version>
 </dependency>
 <!-- https://mvnrepository.com/artifact/net.sf.json-lib/json-lib -->
 <dependency>
 <groupId>net.sf.json-lib</groupId>
 <artifactId>json-lib</artifactId>
 <version>2.4</version>
 <classifier>jdk15</classifier>
 </dependency>
 <!-- https://mvnrepository.com/artifact/org.activiti/activiti-engine -->
 <dependency>
 <groupId>org.activiti</groupId>
 <artifactId>activiti-engine</artifactId>
 <version>${activiti.version}</version>
 <exclusions>
 <exclusion>
 <groupId>org.mybatis</groupId>
 <artifactId>mybatis</artifactId>
 </exclusion>
 </exclusions>
 </dependency>
 <!--沒有會引起mybaits plus通用mapper和activity的沖突-->
 <dependency>
 <groupId>org.activiti</groupId>
 <artifactId>activiti-spring-boot-starter-jpa</artifactId>
 <version>${activiti.version}</version>
 </dependency>
 <dependency>
 <groupId>org.apache.poi</groupId>
 <artifactId>poi</artifactId>
 <version>${poi.version}</version>
 </dependency>
 <!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
 <dependency>
 <groupId>org.apache.poi</groupId>
 <artifactId>poi-ooxml</artifactId>
 <version>${poi.version}</version>
 </dependency>
 </dependencies>
 </dependencyManagement>
</project>

第二個是honor-common

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<project xmlns="http://maven.apache.org/POM/4.0.0"
 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">
 <parent>
 <artifactId>phone</artifactId>
 <groupId>com.honor</groupId>
 <version>1.0-SNAPSHOT</version>
 </parent>
 <modelVersion>4.0.0</modelVersion>
 <artifactId>honor-common</artifactId>
 <dependencies>
 <dependency>
 <groupId>org.projectlombok</groupId>
 <artifactId>lombok</artifactId>
 </dependency>
 <dependency>
 <groupId>com.baomidou</groupId>
 <artifactId>mybatis-plus-annotation</artifactId>
 <version>3.1.0</version>
 <scope>compile</scope>
 </dependency>
 </dependencies>
</project>

 第三個是honor-dao的 pom

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<project xmlns="http://maven.apache.org/POM/4.0.0"
 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">
 <parent>
 <artifactId>phone</artifactId>
 <groupId>com.honor</groupId>
 <version>1.0-SNAPSHOT</version>
 </parent>
 <modelVersion>4.0.0</modelVersion>
 
 <artifactId>honor-dao</artifactId>
 
 <dependencies>
 <dependency>
 <groupId>com.honor</groupId>
 <artifactId>honor-common</artifactId>
 </dependency>
 
 <dependency>
 <groupId>com.baomidou</groupId>
 <artifactId>mybatis-plus-boot-starter</artifactId>
 </dependency>
 <dependency>
 <groupId>com.baomidou</groupId>
 <artifactId>mybatis-plus-generator</artifactId>
 </dependency>
 <dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 </dependency>
 </dependencies>
</project>

第四個是honor-manager的 

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<project xmlns="http://maven.apache.org/POM/4.0.0"
 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">
 <parent>
 <artifactId>phone</artifactId>
 <groupId>com.honor</groupId>
 <version>1.0-SNAPSHOT</version>
 </parent>
 <modelVersion>4.0.0</modelVersion>
 
 
 <groupId>com.honor.manager</groupId>
 <artifactId>honor-manager</artifactId>
 <packaging>pom</packaging>
 <modules>
 <module>honor-manager-txn1</module>
 <module>honor-manager-user1</module>
 <module>honor-manager-boot</module>
 </modules>
 <dependencies>
 <dependency>
 <groupId>com.honor</groupId>
 <artifactId>honor-common</artifactId>
 </dependency>
 <dependency>
 <groupId>com.honor</groupId>
 <artifactId>honor-dao</artifactId>
 </dependency>
 <dependency>
 <groupId>com.baomidou</groupId>
 <artifactId>mybatis-plus-boot-starter</artifactId>
 </dependency>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
 </dependencies>
 <dependencyManagement>
 <dependencies>
 <dependency>
 <groupId>com.honor.manager</groupId>
 <artifactId>honor-manager-boot</artifactId>
 <version>1.0-SNAPSHOT</version>
 </dependency>
 <dependency>
 <groupId>com.honor.manager</groupId>
 <artifactId>>honor-manager-txn1</artifactId>
 <version>1.0-SNAPSHOT</version>
 </dependency>
 <dependency>
 <groupId>com.honor.manager</groupId>
 <artifactId>>honor-manager-user1</artifactId>
 <version>1.0-SNAPSHOT</version>
 </dependency>
 </dependencies>
 </dependencyManagement>
</project>

然后 是 honor-manager-user

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<project xmlns="http://maven.apache.org/POM/4.0.0"
 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">
 <parent>
 <artifactId>honor-manager</artifactId>
 <groupId>com.honor.manager</groupId>
 <version>1.0-SNAPSHOT</version>
 </parent>
 <modelVersion>4.0.0</modelVersion>
 <artifactId>honor-manager-user1</artifactId>
 <dependencies>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
 </dependencies>
</project>

然后 是honor-manager-boot記得boot 要引入 txn1 和 user的依賴,記得要把parents 要改一下,是為honor-manager. 

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <parent>
 <artifactId>honor-manager</artifactId>
 <groupId>com.honor.manager</groupId>
 <version>1.0-SNAPSHOT</version>
 </parent>
 <groupId>com.honor.manager</groupId>
 <artifactId>honor-manager-boot</artifactId>
 <version>0.0.1-SNAPSHOT</version>
 <name>honor-manager-boot</name>
 <description>Demo project for Spring Boot</description>
 <properties>
 <java.version>1.8</java.version>
 </properties>
 <dependencies>
 <dependency>
 <groupId>com.honor.manager</groupId>
 <artifactId>honor-manager-user1</artifactId>
 <version>1.0-SNAPSHOT</version>
 </dependency>
 <dependency>
 <groupId>com.honor.manager</groupId>
 <artifactId>honor-manager-txn1</artifactId>
 <version>1.0-SNAPSHOT</version>
 </dependency>
 <dependency>
 <groupId>mysql</groupId>
 <artifactId>mysql-connector-java</artifactId>
 <scope>runtime</scope>
 </dependency>
 <dependency>
 <groupId>org.junit.jupiter</groupId>
 <artifactId>junit-jupiter-api</artifactId>
 </dependency>
 <dependency>
 <groupId>com.alibaba</groupId>
 <artifactId>druid-spring-boot-starter</artifactId>
 </dependency>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-web</artifactId>
 </dependency>
 <dependency>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-test</artifactId>
 <scope>test</scope>
 <exclusions>
 <exclusion>
 <groupId>org.junit.vintage</groupId>
 <artifactId>junit-vintage-engine</artifactId>
 </exclusion>
 </exclusions>
 </dependency>
 <dependency>
 <groupId>org.junit.jupiter</groupId>
 <artifactId>junit-jupiter</artifactId>
 <version>RELEASE</version>
 <scope>test</scope>
 </dependency>
 </dependencies>
 <build>
 <plugins>
 <plugin>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-maven-plugin</artifactId>
 </plugin>
 </plugins>
 </build>
</project>

  第二階段  開始測試 首先搭建數據庫,做個簡單的User 表測試就行了 

springboot+idea+maven多模塊項目搭建的方法 

然后搭建 beans 

springboot+idea+maven多模塊項目搭建的方法 

User 的內容

package com.honor.common.beans;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class User {
 @TableId(type = IdType.AUTO)
 private Integer id;
 private String username;
 private String password;
}

第二部 dao層

springboot+idea+maven多模塊項目搭建的方法

UserMapper接口

package com.honor.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.honor.common.beans.User;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface UserMapper extends BaseMapper<User> {
}

UserMapper.xml

<&#63;xml version="1.0" encoding="UTF-8"&#63;>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.honor.mapper.UserMapper">
 <resultMap id="User" type="com.eft.common.beans.User"/>
</mapper>

第三部分 springboot 的application 中加入掃描包的注解

springboot+idea+maven多模塊項目搭建的方法 

@ServletComponentScan
 
@MapperScan("com.honor.mapper")

  然后編寫application.yml 文件 

server:
 port: 8880
 servlet:
 context-path: /honor-manager
 
spring:
 application:
 name: users
 datasource:
 type: com.alibaba.druid.pool.DruidDataSource
 driver-class-name: com.mysql.jdbc.Driver
 url: jdbc:mysql://localhost:3306/eft&#63;characterEncoding=UTF-8&serverTimezone=UTC&useSSL=true
 username: root
 password: 111111
mybatis-plus:
 mapper-locations:
 - classpath*:com/honor/mapper/*.xml
 check-config-location: true
debug: true

緊接著編寫 userController 進行測試一定要前綴一樣!這里注意要前綴一樣,要不 掃描不到    

springboot+idea+maven多模塊項目搭建的方法

UserController代碼

package com.honor.manager.controller;
import com.honor.common.beans.User;
import com.honor.mapper.UserMapper;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Map;
@RestController
public class UserController {
 @Resource
 UserMapper userMapper;
 @RequestMapping(
 value = "/api/user",
 method = RequestMethod.GET,
 produces = MediaType.APPLICATION_JSON_UTF8_VALUE
 )
 @ResponseBody
 public User read(@RequestParam Map<String, Object> params) {
 return userMapper.selectById("1");
 }
 @GetMapping("/api/test")
 public String hello() {
 return "hello";
 }
}

訪問 http://localhost:8880/honor-manager/api/user

springboot+idea+maven多模塊項目搭建的方法 自

此 多級模塊的項目就搭建成功了!

感謝各位的閱讀!關于springboot+idea+maven多模塊項目搭建的方法就分享到這里了,希望以上內容可以對大家有一定的幫助,讓大家可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

江安县| 盐山县| 新和县| 沈阳市| 金堂县| 怀宁县| 和田市| 公安县| 保定市| 东平县| 德格县| 磴口县| 枞阳县| 保靖县| 扶风县| 大港区| 平陆县| 马鞍山市| 株洲县| 铁岭县| 肇东市| 会昌县| 武城县| 东莞市| 社旗县| 岳西县| 和顺县| 仲巴县| 玉林市| 绥芬河市| 任丘市| 仁怀市| 南康市| 迭部县| 祁东县| 宁城县| 宁陵县| 杂多县| 芜湖市| 文水县| 龙江县|