摘要:添加簡(jiǎn)單用戶微服務(wù)啟動(dòng)類簡(jiǎn)單用戶微服務(wù)類支持熱部署。
SpringCloud(第 038 篇)idea環(huán)境熱部署微服務(wù)開發(fā)
-
一、大致介紹1、我們?cè)陂_發(fā)過程中,會(huì)經(jīng)常需要啟動(dòng)、停止微服務(wù),而且有時(shí)候會(huì)比較頻繁,需要不停的操作啟停動(dòng)作; 2、而我們本章節(jié)主要講解下如何在開發(fā)環(huán)境中進(jìn)行熱部署,這樣的話可以在一定程度上專心敲代碼,兩耳不聞窗外事,一心只想敲代碼;二、實(shí)現(xiàn)步驟 2.1 添加 maven 引用包
2.2 添加應(yīng)用配置文件(springms-simple-provider-user-devtoolssrcmainresourcesapplication.yml)4.0.0 springms-simple-provider-user-devtools 1.0-SNAPSHOT jar com.springms.cloud springms-spring-cloud 1.0-SNAPSHOT org.springframework.boot spring-boot-starter-data-jpa org.springframework.boot spring-boot-starter-web com.h2database h2 runtime org.springframework.boot spring-boot-starter-data-solr org.springframework.boot spring-boot-devtools true org.springframework.boot spring-boot-maven-plugin true
server: port: 8305 spring: application: name: springms-simple-provider-user-devtools #全部小寫 jpa: generate-ddl: false show-sql: true hibernate: ddl-auto: none datasource: platform: h2 schema: classpath:schema.sql data: classpath:data.sql thymeleaf: cache: false logging: level: root: INFO org.hibernate: INFO org.hibernate.type.descriptor.sql.BasicBinder: TRACE org.hibernate.type.descriptor.sql.BasicExtractor: TRACE com.springms: DEBUG2.3 添加 H2 數(shù)據(jù)庫(kù)腳本(springms-simple-provider-user-devtoolssrcmainresourcesschema.sql)
drop table user if exists; CREATE TABLE USER( id BIGINT GENERATED by default as identity, username VARCHAR(40), name VARCHAR(20), age int(3), balance DECIMAL(10, 2), PRIMARY KEY(id) );2.4 插入 H2 數(shù)據(jù)庫(kù)一些初始化數(shù)據(jù)(springms-simple-provider-user-devtoolssrcmainresourcesdata.sql)
INSERT into user (id, username, name, age, balance) values (1, "user1", "張三", 20, 100.00); INSERT into user (id, username, name, age, balance) values (2, "user2", "李四", 22, 100.00); INSERT into user (id, username, name, age, balance) values (3, "user3", "王五", 24, 100.00); INSERT into user (id, username, name, age, balance) values (4, "user4", "趙六", 26, 100.00); INSERT into user (id, username, name, age, balance) values (5, "user5", "李逵", 27, 100.00); INSERT into user (id, username, name, age, balance) values (6, "user6", "張遠(yuǎn)", 10, 100.00); INSERT into user (id, username, name, age, balance) values (7, "user7", "迪拜", 60, 100.00); INSERT into user (id, username, name, age, balance) values (8, "user8", "哈士奇", 40, 100.00); INSERT into user (id, username, name, age, balance) values (9, "user9", "關(guān)羽", 30, 100.00);2.5 添加訪問底層數(shù)據(jù)模型的DAO接口(springms-simple-provider-user-devtoolssrcmainjavacomspringmscloudrepositoryUserRepository.java)
package com.springms.cloud.repository; import com.springms.cloud.entity.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface UserRepository extends JpaRepository2.6 添加實(shí)體用戶類User(springms-simple-provider-user-devtoolssrcmainjavacomspringmscloudentityUser.java){ }
package com.springms.cloud.entity; import java.math.BigDecimal; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity public class User { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @Column private String username; @Column private String name; @Column private Short age; @Column private BigDecimal balance; public Long getId() { return this.id; } public void setId(Long id) { this.id = id; } public String getUsername() { return this.username; } public void setUsername(String username) { this.username = username; } public String getName() { return this.name; } public void setName(String name) { this.name = name; } public Short getAge() { return this.age; } public void setAge(Short age) { this.age = age; } public BigDecimal getBalance() { return this.balance; } public void setBalance(BigDecimal balance) { this.balance = balance; } }2.7 添加用戶Web訪問層Controller(springms-simple-provider-user-devtools/src/main/java/com/springms/cloud/controller/SimpleProviderUserDevtoolsController.java)
package com.springms.cloud.controller; import com.springms.cloud.entity.User; import com.springms.cloud.repository.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; /** * 用戶微服務(wù)Controller(支持 idea 熱部署)。 * * @author hmilyylimh * * @version 0.0.1 * * @date 17/10/18 * */ @RestController public class SimpleProviderUserDevtoolsController { @Autowired private UserRepository userRepository; @GetMapping("/simple/{id}") public User findById(@PathVariable Long id) { return this.userRepository.findOne(id); } @GetMapping("simple") public String simple() { return "simple-2017-09"; } @GetMapping("simple2") public String simple2() { return "simple2-2017"; } }2.8 添加簡(jiǎn)單用戶微服務(wù)啟動(dòng)類(springms-simple-provider-user-devtoolssrcmainjavacomspringmscloudMsSimpleProviderUserApplication.java)
package com.springms.cloud; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * 簡(jiǎn)單用戶微服務(wù)類(支持 idea 熱部署)。 * * @author hmilyylimh * * @version 0.0.1 * * @date 17/10/18 * */ @SpringBootApplication public class MsSimpleProviderUserDevtoolsApplication { public static void main(String[] args) { SpringApplication.run(MsSimpleProviderUserDevtoolsApplication.class, args); System.out.println("【【【【【【 簡(jiǎn)單用戶微服務(wù)(熱部署) 】】】】】】已啟動(dòng)."); } }三、測(cè)試
/**************************************************************************************** 一、簡(jiǎn)單用戶微服務(wù)接口測(cè)試: 1、添加 spring-boot-devtools 熱部署依賴; 2、pom.xml 添加四、下載地址true 屬性; 3、設(shè)置 idea 屬性:“File” -> “Settings” -> “Build,Execution,Deplyment” -> “Compiler”,選中打勾 “Build project automatically” ; 4、設(shè)置 idea 屬性:組合鍵:“Shift+Ctrl+Alt+/” ,選擇 “Registry” ,選中打勾 “compiler.automake.allow.when.app.running” ; 5、設(shè)置緩存配置 spring.thymeleaf.cache=false; 6、設(shè)置 chrome 屬性:F12或者“Ctrl+Shift+I”,打開開發(fā)者工具,“Network” 選項(xiàng)卡下 選中打勾 “Disable Cache(while DevTools is open)” ; 7、啟動(dòng) springms-simple-provider-user-devtools 模塊服務(wù),啟動(dòng)1個(gè)端口; 8、在瀏覽器輸入地址 http://localhost:8305/simple 可以看到信息成功的被打印出來; 9、改動(dòng) Controller 某個(gè)方法的返回值,或者新增方法,然后會(huì)看到控制臺(tái)自動(dòng)重啟該應(yīng)用,進(jìn)行熱部署; 10、再在瀏覽器請(qǐng)求剛剛改動(dòng)的鏈接,發(fā)現(xiàn)鏈接返回的內(nèi)容確實(shí)動(dòng)態(tài)改變過來了,這就是熱部署; ****************************************************************************************/
https://gitee.com/ylimhhmily/SpringCloudTutorial.git
SpringCloudTutorial交流QQ群: 235322432
SpringCloudTutorial交流微信群: 微信溝通群二維碼圖片鏈接
歡迎關(guān)注,您的肯定是對(duì)我最大的支持!!!
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/67802.html
摘要:第篇中用部署一個(gè)簡(jiǎn)單的基于服務(wù)治理發(fā)現(xiàn)的項(xiàng)目一大致介紹糾結(jié)了一下下,這么簡(jiǎn)單的部署流程是否需要詳細(xì)的貼出來,然而糾結(jié)了一下還是將這個(gè)簡(jiǎn)單的部署流程補(bǔ)充完整了經(jīng)過上節(jié)的講解,相信大家已經(jīng)對(duì)的命令操作都有了一定的了解,這里我就暫且默認(rèn)大家都擁 SpringCloud(第 053 篇)CentOS7 中用 Docker 部署一個(gè)簡(jiǎn)單的基于 Eureka 服務(wù)治理發(fā)現(xiàn)的項(xiàng)目 - 一、大致介紹 ...
摘要:第篇中用部署一個(gè)簡(jiǎn)單的基于服務(wù)治理發(fā)現(xiàn)的項(xiàng)目一大致介紹糾結(jié)了一下下,這么簡(jiǎn)單的部署流程是否需要詳細(xì)的貼出來,然而糾結(jié)了一下還是將這個(gè)簡(jiǎn)單的部署流程補(bǔ)充完整了經(jīng)過上節(jié)的講解,相信大家已經(jīng)對(duì)的命令操作都有了一定的了解,這里我就暫且默認(rèn)大家都擁 SpringCloud(第 053 篇)CentOS7 中用 Docker 部署一個(gè)簡(jiǎn)單的基于 Eureka 服務(wù)治理發(fā)現(xiàn)的項(xiàng)目 - 一、大致介紹 ...
摘要:是一個(gè)相對(duì)比較新的微服務(wù)框架,年才推出的版本雖然時(shí)間最短但是相比等框架提供的全套的分布式系統(tǒng)解決方案。提供線程池不同的服務(wù)走不同的線程池,實(shí)現(xiàn)了不同服務(wù)調(diào)用的隔離,避免了服務(wù)器雪崩的問題。通過互相注冊(cè)的方式來進(jìn)行消息同步和保證高可用。 Spring Cloud 是一個(gè)相對(duì)比較新的微服務(wù)框架,...
摘要:我不聽,我就是這么命名。任何服務(wù)啟動(dòng)以后,都會(huì)把自己注冊(cè)到的注冊(cè)表中當(dāng)服務(wù)死亡的時(shí)候,也會(huì)通知。服務(wù)拿到結(jié)果后,會(huì)把結(jié)果緩存在本地的注冊(cè)表里。根據(jù)負(fù)載均衡策略,從注冊(cè)表中選擇一個(gè)真正的實(shí)例地址。 原創(chuàng):小姐姐味道(微信公眾號(hào)ID:xjjdog),歡迎分享,轉(zhuǎn)載請(qǐng)保留出處。 這幾天可真是熱啊,泡個(gè)海澡是再好不過了。玩的正起勁,突然腳底絆上一股暗流,然后我就一直在水里旋轉(zhuǎn)旋轉(zhuǎn)旋轉(zhuǎn)...終于...
閱讀 1987·2021-11-23 10:03
閱讀 4193·2021-11-22 09:34
閱讀 2495·2021-10-08 10:05
閱讀 2259·2019-08-30 15:53
閱讀 1698·2019-08-30 13:56
閱讀 1169·2019-08-29 16:52
閱讀 1118·2019-08-26 13:31
閱讀 3358·2019-08-26 11:45