spring boot建立多模組專案
1:先建立一個聚合工程parent
<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.yonmei</groupId> <artifactId>taobao-parent</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <!-- 繼承說明:這裡繼承SpringBoot提供的父工程 --> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.7.RELEASE</version> <relativePath/> </parent> <modules> <module>taobao-interface</module> <module>taobao-service</module> <module>taobao-entity</module> <module>taobao-web</module> </modules> <!-- 版本說明:這裡統一管理依賴的版本號 --> <dependencyManagement> <dependencies> <dependency> <groupId>com.yonmei</groupId> <artifactId>taobao-web</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>com.yonmei</groupId> <artifactId>taobao-service</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>com.yonmei</groupId> <artifactId>taobao-interface</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>com.yonmei</groupId> <artifactId>taobao-entity</artifactId> <version>0.0.1-SNAPSHOT</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.42</version> </dependency> </dependencies> </dependencyManagement> </project>
2:建立公共專案common
<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> <parent> <groupId>com.yonmei</groupId> <artifactId>taobao-parent</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <groupId>com.yonmei</groupId> <artifactId>taobao-common</artifactId> <version>0.0.1-SNAPSHOT</version> </project>
3:建立parent的子模組(mapper,service,interface都是一樣的,其中web的有點特殊!)
這裡就演示service模組的建立
<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>
<parent>
<groupId>com.yonmei</groupId>
<artifactId>taobao-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>taobao-service</artifactId>
<dependencies>
<dependency>
<groupId>com.yonmei</groupId>
<artifactId>taobao-interface</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.yonmei</groupId>
<artifactId>taobao-entity</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
package com.gwm.service;
import org.springframework.stereotype.Service;
import com.gwm.api.UsersService;
import com.gwm.entity.Users;
@Service
public class UsersServiceImpl implements UsersService {
@Override
public String getUsersInfo(Users users) {
System.out.println("springboot de ipml"+users);
return "hellow springboot";
}
}
4:建立web模組
<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>
<parent>
<groupId>com.yonmei</groupId>
<artifactId>taobao-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>taobao-web</artifactId>
<dependencies>
<dependency>
<groupId>com.yonmei</groupId>
<artifactId>taobao-interface</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yonmei</groupId>
<artifactId>taobao-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yonmei</groupId>
<artifactId>taobao-entity</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
4.1: UsersController類的程式碼如下所示!
package com.gwm.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gwm.api.UsersService;
import com.gwm.entity.Users;
@RestController
@RequestMapping("users")
public class UsersController {
@Autowired
private UsersService usersService;
@RequestMapping("/getUserInfo")
public String getString(){
System.out.println("userInfo:="+usersService.getUsersInfo(new Users("gwm","123456")));
return usersService.getUsersInfo(new Users("gwm","123456"));
}
}
4.2:啟動類的程式碼如下所示
package com.gwm.controller;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/*
* 1:可以載入一個掃描配置檔案
* */
import org.springframework.context.annotation.ComponentScan;
@ComponentScan(basePackages={"com.gwm"})
@SpringBootApplication
public class StarterApplication {
public static void main(String[] args) {
SpringApplication.run(StarterApplication.class, args);
}
}
4.3:上述啟動類中需要注意到的是,這裡有可能會報一個錯誤,錯誤的原因是因spring boot自動掃描沒有找到bean,所以我們可以自己加一個註解配置,自己指定需要掃描的檔案或者類,這個配置就是:@ComponentScan(basePackages={"com.gwm"})
5:需要打包web的時候就需要在含有啟動類(也就是controller類)的模組中新增一個外掛(一段程式碼),其中打包的命令是
package,如果是打包war,就要將web層的pom的打包方式改為war,直接放到tomcat中去即可,如果是jar,那麼需要找到該jar的目錄,然後執行java -jar xx.xx.xx.jar即可!
<build>
<finalName>first-spintboot-project</finalName>
<plugins>
<plugin>
<!--該外掛主要用途:構建可執行的JAR -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
另外一個博主講的是IDEA建立springboot專案的流程點選開啟連結
相關推薦
spring boot建立多模組專案
1:先建立一個聚合工程parent<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLoc
Spring Boot2企業版快速開發平臺ALBase(2): 使用Maven建立多模組專案
系統模組劃分 Maven多模組專案,適用於一些比較大的專案,通過合理的模組拆分,實現程式碼的複用,便於維護和管理。尤其是一些開源框架,也是採用多模組的方式,提供外掛整合,使用者可以根據需要配置指定的模組。 專案結構如下: albase (父
利用springboot建立多模組專案
本文旨在用最通俗的語言講述最枯燥的基本知識 最近要對一個不大不小的專案進行重構,用spring覺得太過於繁瑣,用cloud又有覺得過於龐大,維護的人手不夠;權衡之下,最終選了springboot作為架子,但是因為專案涉及的業務模組較多,各個模組之間的業務交流不是很多,相對獨立,因此想著把專案做成多模組
IDEA springboot 建立多模組專案,打包
原始碼:https://gitee.com/DencyCheng/springboot-multiModule/tree/dev 1.專案結構 2.專案依賴關係 multi-module :外層專案 model:實體類 persistence:持久化物件 web:控
Spring-boot構建多模組依賴工程時,maven打包異常:程式包xxx不存在
在qizhi專案改版的時候, 所有程式碼都遷移好了, 但是compile的時候報程式包*****不存在, 具體到某一個類就是: 找不到符號. 下面這篇文章是正解 http://hbxflihua.iteye.com/blog/2431537 具體內容如下: =======================
基於maven使用IDEA建立多模組專案
鑑於最近學習一個分散式專案的開發,講一下關於使用IntelliJ IDEA基於Maven建立多模組專案的實際開發,可能有不合適的地方,但是專案是可以跑通的,也請有不足之處,都提出來,一起討論下。 一. 專案工程目錄 首先展示一下,最終整個專案的工程目錄
gradle建立多模組專案
第一種方式視覺化的:使用eclipse建立多模組專案示例 新建子專案 按嚮導新建專案gradleFirst 按嚮導新建專案gradleSecond(過程略) 按嚮導新建專案gradleParent(過程略) 完整的專案列表結構如下
idea Maven建立多模組專案(之單元測試)
前面兩篇已經建立好子模組,且各自關聯起來,接下來進行單元測試在idea中引入單元測試junit非常方便;選中類名右擊--->goto---->Test---->create new test;如圖:選擇需要的junit jar包,如圖:點選OK完成,然後ma
intellij用maven來建立多模組專案
Maven 與 IntelliJ IDEA 的完美結合 可以先看看這個帖子,用intellij來maven構建多模組工程還是有很多好處的。 IntelliJ IDEA借鑑的Maven的概念,不在採取Eclipse裡Project的概念,一切都是Module。無論是
46、Maven建立多模組專案(多個war,2017版Eclipse Neon.2)
執行環境: 2017年3月 Eclipse Neon.2 Apache Maven 3.3.9 jdk1.8 注意,此文跟網上所有的建立maven專案有所不同, 就是都會勾選 create a simple project,網上的都是不勾選的。下面就不額外提出了。 首先
idea使用maven-archetype-webapp建立多模組專案無java資料夾和resources資料夾
1.原始專案結構圖 2.建立新的子專案,右鍵model->new model,選中create from archetype 3.填寫專案相關資訊 4.系統根據模板生成相應的資料夾 5.觀察圖片發現缺少java和resources資
idea(二)--idea中建立多模組專案、maven多模組開發
一、idea中建立多模組專案(多工程同時開發) 熟悉eclipse、myeclipse的人都知道,eclipse、myeclipse中都有工作的空間(workspace)的概念,一個workspace中可以建立多個project,即可同時開啟多個專案進行開發。然而,遺憾的是
Eclipse建立多模組Spring boot專案
1、安裝sts工具 開啟Eclipse,選擇Help -> Eclipse Marketplace… Search或選擇“Popular”標籤,搜尋spring,選擇Spring Tool Suite (STS) for Eclipse外掛,安裝 2、new project
Spring Boot 多模組專案建立
一.前言 maven多模組專案通常由一個父模組和若干個子模組構成,每個模組都對應著一個pom.xml。它們之間通過繼承和聚合(也稱作多模組)相互關聯。多模組適用於一些比較大的專案,通過合理的模組拆分,實現程式碼的複用,便於維護和管理。例如Dubbo專案的多模組建立 二.建立專案
Spring Boot 多模組專案建立與配置
springboot 分模組 開發 部落格地址:點選開啟連結maven多模組專案通常由一個父模組和若干個子模組構成,每個模組都對應著一個pom.xml。它們之間通過繼承和聚合(也稱作多模組)相互關聯。多模組適用於一些比較大的專案,通過合理的模組拆分,實現程式碼的複用,便於維護
Maven 搭建spring boot多模組專案
轉自:https://segmentfault.com/a/1190000005020589 備註:所有專案都在idea中建立 1.idea建立maven專案(Project) 1-1: file > new > project 輸入 groupId和a
Spring-boot教程(十四)多模組專案遇到的整合問題
1、多模組專案只能在程式啟動所在的模組有application,所以對於多模組專案來說,必須解決各個模組的配置檔案能夠被專案正確讀取的問題。 這裡採用@Configuration手動配置各種第三方框架,如mysql、mybatis、redis.... 這裡採用@Prope
Maven搭建spring boot多模組專案打jar war zip 包方式
Spring boot 父專案聚合以下模組,下圖是parent.pom:其中controller是web模組,各個模組的依賴關係如下:由於spring boot 內嵌了servlet容器,而且提供了專案的java -jar啟動方式,所以可以把所有模組都打為jar包形式:con
Sping Boot多模組專案的建立和配置
在SpringCloud分散式微服務當中,我們需要建立很多個微服務,假如所有的微服務都分開編寫,不方便我們的閱讀和編碼,何況一個人有可能一次性負責很多個模組。因此,我們可以利用SpringBoot的多模組開發,一個模組就是一個微服務的應用,方便我們去整體性的編寫程式碼,後期的
idea 快速搭建spring boot 多模組專案(底部附原始碼)
第一步 :建立父maven 模組,新建一個spring boot專案 父類pom.xml <?xml version