在线观看www成人影院-在线观看www日本免费网站-在线观看www视频-在线观看操-欧美18在线-欧美1级

0
  • 聊天消息
  • 系統(tǒng)消息
  • 評(píng)論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會(huì)員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識(shí)你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

什么是springBoot業(yè)務(wù)組件化開(kāi)發(fā)?談?wù)凷pringBoot業(yè)務(wù)組件化

jf_ro2CN3Fa ? 來(lái)源:csdn ? 2023-07-20 11:30 ? 次閱讀

1、背景

首先,談一談什么是“springBoot業(yè)務(wù)組件化開(kāi)發(fā)”,最近一直在開(kāi)發(fā)一直面臨這一個(gè)問(wèn)題,就是相同的業(yè)務(wù)場(chǎng)景場(chǎng)景在一個(gè)項(xiàng)目中使用了,又需要再另外一個(gè)項(xiàng)目中復(fù)用,一遍又一遍的復(fù)制代碼,然后想將該業(yè)務(wù)的代碼在不同的項(xiàng)目中維護(hù)起來(lái)真的很難。

最開(kāi)始想用微服務(wù)的方式來(lái)解決這個(gè)問(wèn)題,但是覺(jué)得一套完整的微服務(wù)太重,而且目前微服務(wù)還處于振蕩期(去年的微服務(wù)解決方案,今年國(guó)內(nèi)直接都換成了阿里的技術(shù)解決方案),此外很多時(shí)候我們接私活,就是個(gè)單體的springboot項(xiàng)目,用不上微服務(wù)這種級(jí)別的項(xiàng)目,所以想來(lái)想去這條路不是很滿足我的需求;再后來(lái),想到單體的聚合架構(gòu),但是聚合架構(gòu)的項(xiàng)目,個(gè)人覺(jué)得有時(shí)候也不是很好,一般的聚合項(xiàng)目就是基于某個(gè)具體實(shí)例架構(gòu)下才能使用,換一個(gè)架構(gòu)自己寫的業(yè)務(wù)model就不能用了(比如你在suoyi框架下開(kāi)發(fā)的模塊業(yè)務(wù)包,在guns下可能就直接不能使用了)。

最后,想了一下,能不能單獨(dú)開(kāi)發(fā)一個(gè)項(xiàng)目,這個(gè)項(xiàng)目可以自己獨(dú)立運(yùn)行(微服務(wù)架構(gòu)下用),也可以在單體項(xiàng)目中直接通過(guò)pom引入的方式,然后簡(jiǎn)單的配置一下,然后直接使用多好;查了一下網(wǎng)上沒(méi)有現(xiàn)成的技術(shù)解決方案,問(wèn)了同事,他說(shuō)我這種思想屬于SOA的一種實(shí)現(xiàn),同時(shí)有第三包和聚合項(xiàng)目的影子在里面。也許有什么更好的技術(shù)解決方案,也希望各位能夠不吝賜教。

補(bǔ)充一句,之所以說(shuō)“業(yè)務(wù)組件化”開(kāi)發(fā),來(lái)源于Vue的思想,希望Java后端開(kāi)發(fā)的業(yè)務(wù)也可像vue的組件一樣去使用,這樣多好

2、demo

2-1項(xiàng)目準(zhǔn)備

①建一個(gè)Java項(xiàng)目項(xiàng)目,結(jié)構(gòu)如下圖:

79523374-269e-11ee-962d-dac502259ad0.png

②pom文件如下:



4.0.0


org.springframework.boot
spring-boot-starter-parent
2.3.1.RELEASE


top.wp
cx-flow
1.0-SNAPSHOT



UTF-8
UTF-8
8.0.17
1.1.21
3.3.2
1.2.70
0.9.1
5.3.7
1.18.12
2.9.2
1.9.6
4.2.0
4.2.0
6.4.3
1.15.6
3.8.0
5.6.23
4.4.6
4.17.6
3.1.57




 

org.springframework.boot
spring-boot-starter-web


 

com.baomidou
mybatis-plus-boot-starter
${mp.version}


 

mysql
mysql-connector-java
${mysql-connector-java.version}


 

com.alibaba
druid
${druid.version}


 

cn.hutool
hutool-all
${hutool.version}


 

org.projectlombok
lombok
${lombok.versin}








src/main/resources
 

**/*.properties
**/*.xml
**/*.yml

false


src/main/java

**/*.xml

false






③配置文件如下:主要是數(shù)據(jù)庫(kù)和mybaits-plus的配置(其實(shí)可以不用這個(gè)配置文件,在這只是為了項(xiàng)目能夠獨(dú)立運(yùn)行起來(lái))

#服務(wù)配置
server:
port:8080
#spring相關(guān)配置
spring:
datasource:
driver-class-name:com.mysql.cj.jdbc.Driver
url:jdbc//localhost:3306/cx-xn?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT&nullCatalogMeansCurrent=true
username:數(shù)據(jù)庫(kù)賬戶
password:數(shù)據(jù)庫(kù)密碼
servlet:
multipart:
max-request-size:100MB
max-file-size:100MB
jackson:
time-zone:GMT+8
date-format:yyyy-MM-ddHHss.SSS
locale:zh_CN
serialization:
#格式化輸出
indent_output:false

#mybaits相關(guān)配置
mybatis-plus:
mapper-locations:classpath*:top/wp/cx/**/mapping/*.xml,classpath:/META-INF/modeler-mybatis-mappings/*.xml
configuration:
map-underscore-to-camel-case:true
cache-enabled:true
lazy-loading-enabled:true
multiple-result-sets-enabled:true
log-impl:org.apache.ibatis.logging.stdout.StdOutImpl

global-config:
banner:false
db-config:
id-type:assign_id
table-underline:true
enable-sql-runner:true
configuration-properties:
prefix:
blobType:BLOB
boolValue:TRUE

④啟動(dòng)入口(可以不用寫,啟動(dòng)入口存在目的是讓項(xiàng)目可以自己跑起來(lái))

packagetop.wp.cx;

importcn.hutool.log.StaticLog;
importorg.springframework.boot.SpringApplication;
importorg.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
publicclassCXApplication{
publicstaticvoidmain(String[]args){
SpringApplication.run(CXApplication.class,args);
StaticLog.info(">>>"+CXApplication.class.getSimpleName()+"啟動(dòng)成功!");

}
}

⑤測(cè)試:entity、result

packagetop.wp.cx.modular.test.entity;

importcom.baomidou.mybatisplus.annotation.IdType;
importcom.baomidou.mybatisplus.annotation.TableId;
importcom.baomidou.mybatisplus.annotation.TableName;
importlombok.Data;


@Data
@TableName("test")
publicclassTest{

/**
*主鍵
*/
@TableId(type=IdType.ASSIGN_ID)
privateIntegerid;

/**
*賬號(hào)
*/
privateStringname;

}
packagetop.wp.cx.modular.test.result;

importlombok.Data;
@Data
publicclassTestResult{

privateIntegerid;

privateStringname;

}

⑥測(cè)試mapper、xml、service和controller

packagetop.wp.cx.modular.test.mapper;

importcom.baomidou.mybatisplus.core.mapper.BaseMapper;
importtop.wp.cx.modular.test.entity.Test;

/**
*系統(tǒng)用戶數(shù)據(jù)范圍mapper接口
*
*@authorxuyuxiang
*@date2020/3/1315:46
*/
//@Mapper
publicinterfaceTestMapperextendsBaseMapper{
}





packagetop.wp.cx.modular.test.service;

importcom.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
importorg.springframework.stereotype.Service;
importtop.wp.cx.modular.test.entity.Test;
importtop.wp.cx.modular.test.mapper.TestMapper;

/**
*一個(gè)service實(shí)現(xiàn)
*
*@authoryubaoshan
*@date2020/4/918:11
*/
@Service
publicclassTestServiceextendsServiceImpl{

}
packagetop.wp.cx.modular.test.controller;

importorg.springframework.web.bind.annotation.GetMapping;
importorg.springframework.web.bind.annotation.RequestMapping;
importorg.springframework.web.bind.annotation.RestController;
importtop.wp.cx.modular.test.entity.Test;
importtop.wp.cx.modular.test.service.TestService;

importjavax.annotation.Resource;
importjava.util.List;

/**
*一個(gè)示例接口
*
*@authoryubaoshan
*@date2020/4/918:09
*/
@RestController
@RequestMapping("/test")
publicclassTestController{

@Resource
privateTestServicetestService;

@GetMapping("")
publicListtestResult(){
returntestService.list();
}

@GetMapping("/2")
publicStringtestResult2(){
return"22";
}
}

至此項(xiàng)目準(zhǔn)備完成,其實(shí)就是簡(jiǎn)單見(jiàn)了一個(gè)測(cè)試項(xiàng)目,此時(shí)如果你按照上面的步驟,寫了啟動(dòng)類和配置項(xiàng)信息,項(xiàng)目是可以獨(dú)立運(yùn)行的。

2-2項(xiàng)目打包、引入、運(yùn)行

①將2-1中的測(cè)試項(xiàng)目進(jìn)行打包:install右鍵第一個(gè)選項(xiàng)

7998771c-269e-11ee-962d-dac502259ad0.png

②此時(shí)你的本地maven倉(cāng)庫(kù)會(huì)出現(xiàn)剛才的項(xiàng)目(當(dāng)然前提是你的idea配置過(guò)本地的maven)

7a082f62-269e-11ee-962d-dac502259ad0.png7a2e12ae-269e-11ee-962d-dac502259ad0.png

③新建另外一個(gè)項(xiàng)目cx-main

7b31d15e-269e-11ee-962d-dac502259ad0.png

④pom文件如下:注意將你剛才的準(zhǔn)備測(cè)試的項(xiàng)目引入進(jìn)來(lái)

7b5e56a2-269e-11ee-962d-dac502259ad0.png



4.0.0


org.springframework.boot
spring-boot-starter-parent
2.3.1.RELEASE


top.wp.cx
cx-main
1.0-SNAPSHOT


UTF-8
UTF-8
8.0.17
1.1.21
3.3.2
1.2.70
0.9.1
5.3.7
1.18.12
2.9.2
1.9.6
4.2.0
4.2.0
6.4.3
1.15.6
3.8.0
5.6.23
4.4.6
4.17.6
3.1.57






top.wp
cx-flow
1.0-SNAPSHOT


 

org.springframework.boot
spring-boot-starter-web


 

com.baomidou
mybatis-plus-boot-starter
${mp.version}


 

mysql
mysql-connector-java
${mysql-connector-java.version}


 

com.alibaba
druid
${druid.version}


 

cn.hutool
hutool-all
${hutool.version}


 

org.projectlombok
lombok
${lombok.versin}





 



src/main/resources
 

**/*.properties
**/*.xml
**/*.yml

false


src/main/java

**/*.xml

false





⑤application.yml配置文件 注意xml的掃描

7b82a796-269e-11ee-962d-dac502259ad0.png

#服務(wù)配置
server:
port:8081
#spring相關(guān)配置
spring:
datasource:
driver-class-name:com.mysql.cj.jdbc.Driver
url:jdbc//localhost:3306/cx-xn?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=CTT&nullCatalogMeansCurrent=true
username:root
password:root
servlet:
multipart:
max-request-size:100MB
max-file-size:100MB
jackson:
time-zone:GMT+8
date-format:yyyy-MM-ddHHss.SSS
locale:zh_CN
serialization:
#格式化輸出
indent_output:false

#mybaits相關(guān)配置
mybatis-plus:
#xml文件掃描
mapper-locations:classpath*:top/wp/cx/**/mapping/*.xml,classpath:/META-INF/modeler-mybatis-mappings/*.xml
configuration:
map-underscore-to-camel-case:true
cache-enabled:true
lazy-loading-enabled:true
multiple-result-sets-enabled:true
log-impl:org.apache.ibatis.logging.stdout.StdOutImpl

global-config:
banner:false
db-config:
id-type:assign_id
table-underline:true
enable-sql-runner:true
configuration-properties:
prefix:
blobType:BLOB
boolValue:TRUE

⑥啟動(dòng)入口,注意spring和mapper掃描

7ba9eed2-269e-11ee-962d-dac502259ad0.png

packagetop.wp.cx.main;

importcn.hutool.log.StaticLog;
importorg.mybatis.spring.annotation.MapperScan;
importorg.springframework.boot.SpringApplication;
importorg.springframework.boot.autoconfigure.SpringBootApplication;
importorg.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages={"top.wp.cx.modular.test"})//spring掃描
@MapperScan(basePackages={"top.wp.cx.modular.test.**.mapper"})//mybatis掃描mapper
publicclassCXApplication{
publicstaticvoidmain(String[]args){
SpringApplication.run(CXApplication.class,args);
StaticLog.info(">>>"+CXApplication.class.getSimpleName()+"啟動(dòng)成功!");
}
}

⑦此時(shí)啟動(dòng)cx-main的項(xiàng)目,訪問(wèn)2-1的測(cè)試controller能訪問(wèn)成功證明配置正確





審核編輯:劉清

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點(diǎn)僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場(chǎng)。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問(wèn)題,請(qǐng)聯(lián)系本站處理。 舉報(bào)投訴
  • SOA
    SOA
    +關(guān)注

    關(guān)注

    1

    文章

    300

    瀏覽量

    28034
  • JAVA語(yǔ)言
    +關(guān)注

    關(guān)注

    0

    文章

    138

    瀏覽量

    20525
  • gun
    gun
    +關(guān)注

    關(guān)注

    0

    文章

    6

    瀏覽量

    7666
  • SpringBoot
    +關(guān)注

    關(guān)注

    0

    文章

    175

    瀏覽量

    322

原文標(biāo)題:談?wù)?SpringBoot 業(yè)務(wù)組件化開(kāi)發(fā)思路

文章出處:【微信號(hào):芋道源碼,微信公眾號(hào):芋道源碼】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。

收藏 人收藏

    評(píng)論

    相關(guān)推薦
    熱點(diǎn)推薦

    SpringBoot中的Druid介紹

    SpringBoot中Druid數(shù)據(jù)源配置
    發(fā)表于 05-07 09:21

    SpringBoot知識(shí)總結(jié)

    SpringBoot干貨學(xué)習(xí)總結(jié)
    發(fā)表于 08-01 10:40

    怎么學(xué)習(xí)SpringBoot

    SpringBoot學(xué)習(xí)之路(X5)- 整合JPA
    發(fā)表于 06-10 14:52

    springboot集成mqtt

    springboot集成mqtt,大綱一.數(shù)據(jù)入庫(kù)1.數(shù)據(jù)入庫(kù)解決方案二.開(kāi)發(fā)實(shí)時(shí)訂閱發(fā)布展示頁(yè)面1.及時(shí)通訊技術(shù)2.技術(shù)整合
    發(fā)表于 07-16 07:53

    怎樣去使用springboot

    怎樣去使用springboot呢?學(xué)習(xí)springboot需要懂得哪些?
    發(fā)表于 10-25 07:13

    SpringBoot應(yīng)用啟動(dòng)運(yùn)行run方法

    )、refreshContext(context);SpringBoot刷新IOC容器【創(chuàng)建IOC容器對(duì)象,并初始容器,創(chuàng)建容器中的每一個(gè)組件】;如果是web應(yīng)用創(chuàng)建**AnnotationConfigEmbeddedWebA
    發(fā)表于 12-20 06:16

    SpringBoot配置嵌入式Servlet

    SpringBoot配置嵌入式Servlet容器定制和修改Servlet容器相關(guān)配置全局配置文件編寫WebServerFactoryCustomizer注冊(cè)Servlet三大組件注冊(cè)Servlet
    發(fā)表于 12-20 06:19

    基于組件業(yè)務(wù)模型的研究與設(shè)計(jì)

    業(yè)務(wù)基礎(chǔ)軟件平臺(tái)的基礎(chǔ)上提出了一個(gè)基于組件業(yè)務(wù)模型的解決方案。該方案由視圖維、通用層次維和生命周期維三個(gè)維度組成,運(yùn)用業(yè)務(wù)模型驅(qū)動(dòng)模式和基于組件
    發(fā)表于 08-04 09:23 ?10次下載

    深入了解SpringBoot的自動(dòng)配置原理

    通過(guò)這篇文章我們來(lái)深入了解SpringBoot的自動(dòng)配置原理,并分析SpringBoot是如何神不知,鬼不覺(jué)的幫我們做了那么多的事情,讓我們只需要關(guān)心業(yè)務(wù)邏輯開(kāi)發(fā)就可以了。
    的頭像 發(fā)表于 04-07 11:22 ?1168次閱讀
    深入了解<b class='flag-5'>SpringBoot</b>的自動(dòng)配置原理

    什么是 SpringBoot

    本文從為什么要有 `SpringBoot`,以及 `SpringBoot` 到底方便在哪里開(kāi)始入手,逐步分析了 `SpringBoot` 自動(dòng)裝配的原理,最后手寫了一個(gè)簡(jiǎn)單的 `start`
    的頭像 發(fā)表于 04-07 11:28 ?1666次閱讀
    什么是 <b class='flag-5'>SpringBoot</b>?

    SpringBoot常用注解及使用方法1

    基于 SpringBoot 平臺(tái)開(kāi)發(fā)的項(xiàng)目數(shù)不勝數(shù),與常規(guī)的基于`Spring`開(kāi)發(fā)的項(xiàng)目最大的不同之處,SpringBoot 里面提供了大量的注解用于快速
    的頭像 發(fā)表于 04-07 11:51 ?870次閱讀

    SpringBoot的核心注解1

    今天跟大家來(lái)探討下SpringBoot的核心注解@SpringBootApplication以及run方法,理解下springBoot為什么不需要XML,達(dá)到零配置
    的頭像 發(fā)表于 04-07 14:34 ?906次閱讀
    <b class='flag-5'>SpringBoot</b>的核心注解1

    使用springboot完成流程的業(yè)務(wù)功能

    使用springboot開(kāi)發(fā)流程使用的接口完成流程的業(yè)務(wù)功能 基于 Spring Boot + MyBatis Plus + Vue Element 實(shí)現(xiàn)的后臺(tái)管理系統(tǒng) + 用戶小程序,支持 RBAC
    的頭像 發(fā)表于 05-15 17:40 ?1129次閱讀
    使用<b class='flag-5'>springboot</b>完成流程的<b class='flag-5'>業(yè)務(wù)</b>功能

    Springboot項(xiàng)目的集成以及具體使用及配置

    ? 概念 核心組件 API介紹 Springboot集成 具體業(yè)務(wù)集成 API使用 ? 前言 項(xiàng)目中需要用到工作流引擎來(lái)設(shè)計(jì)部分業(yè)務(wù)流程,框架選型最終選擇了 Camunda7,關(guān)于 C
    的頭像 發(fā)表于 07-03 11:18 ?1820次閱讀
    <b class='flag-5'>Springboot</b>項(xiàng)目的集成以及具體使用及配置

    javaweb和springboot能一起用嗎

    JavaWeb 和 SpringBoot 是兩種針對(duì) Java 程序開(kāi)發(fā)的框架,它們可以在一起使用。在本文中,我將詳細(xì)介紹 JavaWeb 和 SpringBoot 的關(guān)系,并探討如何結(jié)合使用這兩個(gè)
    的頭像 發(fā)表于 11-16 10:54 ?2864次閱讀
    主站蜘蛛池模板: 夜夜骑夜夜操 | 在线播放免费人成毛片乱码 | 男男h啪肉np文总受 男男h全肉耽污 | 四虎影院免费在线播放 | 欧美18同性gay视频 | 又粗又大又爽又色又过瘾视频 | 亚洲免费国产 | 婷婷资源综合 | 午夜精品久视频在线观看 | 四虎4hu影库永久地址 | 成年大片免费视频播放手机不卡 | 黄色一级大片视频 | 日韩亚洲欧洲在线rrrr片 | 天堂网在线最新版www中文网 | 新版天堂中文在线8官网 | 婷婷六月丁香午夜爱爱 | 午夜视频观看 | 毛片在线播 | 久久99久久精品国产99热 | 男女交性永久免费视频播放 | 视频精品一区二区三区 | 国产三级观看久久 | 亚洲人成网站在线观看妞妞网 | 亚洲欧美色鬼久久综合 | 亚洲 欧美 自拍 另类 欧美 | 天天操免费视频 | 久久久精品久久久久久久久久久 | 欧美肉到失禁高h视频在线 欧美三级成人 | 性欧美处 | 一级黄色大全 | 四虎久久精品国产 | 婷婷综合 在线 | 男男浪荡双性受hplay | 高清不卡一区 | 91精品啪在线观看国产日本 | 另类free性欧美护士 | 美国一级毛片免费看成人 | 又粗又长又爽又长黄免费视频 | 三级视频网站在线观看 | 久久精品国产99精品最新 | 日本三级s级在线播放 |