SpringCloud?Eureka服務(wù)注冊與發(fā)現(xiàn)實踐
一、Eureka基礎(chǔ)知識概述
1.Eureka兩個核心組件
- Eureka Server :服務(wù)注冊中心,主要用于提供服務(wù)注冊功能。
當(dāng)微服務(wù)啟動時,會將自己的服務(wù)注冊 到 Eureka Server。Eureka Server 維護(hù)了一個可用服務(wù)列表,存儲了所有注冊到 Eureka Server 的可用服務(wù)的信息,這些可用服務(wù)可以在 Eureka Server 的管理界面中直觀看到
- Eureka Client :客戶端,通常指的是微服務(wù)系統(tǒng)中各個微服務(wù),主要用于和 Eureka Server 進(jìn)行交互。
在微服務(wù)應(yīng)用啟動后,Eureka Client 會向 Eureka Server 發(fā)送心跳(默認(rèn)周期為 30 秒)。若 Eureka Server 在多個心跳周期內(nèi)沒有接收到某個 Eureka Client 的心跳,Eureka Server 將它從可用服務(wù)列表中移除(默認(rèn) 90 秒)
Eureka的心跳機(jī)制主要用于確??蛻舳耍ǚ?wù)提供者)與服務(wù)器(服務(wù)注冊中心)之間的連接活性??蛻舳藛雍?,會定期向服務(wù)器發(fā)送心跳數(shù)據(jù),以告知服務(wù)器自己仍然處于活動狀態(tài)
2.Eureka 服務(wù)注冊與發(fā)現(xiàn)

- 服務(wù)注冊中心(Register Service): 它是一個 Eureka Server,用于提供服務(wù)注冊和發(fā)現(xiàn)功能。
- 服務(wù)提供者(Provider Service): 它是一個 Eureka Client,用于提供服務(wù)。它將自己提供的服務(wù)注冊到服務(wù)注冊中心,以供服務(wù)消費者發(fā)現(xiàn)。
- 服務(wù)消費者(Consumer Service): 它是一個 Eureka Client,用于消費服務(wù)。它可以從服務(wù)注冊中心獲取服務(wù)列表,調(diào)用所需的服務(wù)。
Eureka 實現(xiàn)服務(wù)注冊與發(fā)現(xiàn)的流程
- 搭建一個Eureka Server作為服務(wù)注冊中心
- 服務(wù)提供者Eureka Client啟動時,會把當(dāng)前服務(wù)器的信息以服務(wù)名(spring.application.name)的方式注冊到服務(wù)注冊中心
- 服務(wù)消費者Eureka Client啟動時,也會向服務(wù)注冊中心注冊
- 服務(wù)消費者還會獲取一份可用路由服務(wù)列表,該列表中包含了所有注冊到服務(wù)注冊中心的服務(wù)信息(包括服務(wù)提供者和自身的信息)
- 在獲得了可用服務(wù)列表后,服務(wù)消費者通過 HTTP 或消息中間件遠(yuǎn)程調(diào)用服務(wù)提供者提供的服務(wù)。
- 服務(wù)注冊中心(Eureka Server)所扮演的角色十分重要,它是服務(wù)提供者和服務(wù)消費者之間的橋梁。服務(wù)提供者只有將自己的服務(wù)注冊到服務(wù)注冊中心才可能被服務(wù)消費者調(diào)用,而服務(wù)消費者也只有通過服務(wù)注冊中心獲取可用服務(wù)列表后,才能調(diào)用所需的服務(wù)。
二、Eureka單機(jī)搭建
1.構(gòu)建父模塊和三個子模塊 分別為注冊中心 eureka-service 倉儲模塊stock-service 訂單模塊 order-service

2.父模塊pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>cloud-02-Eureka-parent</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>cloud-eureka-service</module>
<module>cloud-stock-service</module>
<module>cloud-order-service</module>
</modules>
<!-- 統(tǒng)一管理jar包版本 -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<junit.version>4.12</junit.version>
<log4j.version>1.2.17</log4j.version>
<lombok.version>1.18.22</lombok.version>
<mysql.version>8.0.24</mysql.version>
<druid.version>1.2.8</druid.version>
<mybatis-plus.version>3.0.7.1</mybatis-plus.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-web -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.2.8</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-jdbc -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>${mybatis-plus.version}</version>
<optional>true</optional>
<exclusions>
<exclusion>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<!-- 子模塊繼承之后,提供作用:鎖定版本+子modlue不用寫groupId和version -->
<dependencyManagement>
<dependencies>
<!--spring boot 2.2.2-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>2.2.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!--spring cloud Hoxton.SR1-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Hoxton.SR1</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
3.對cloud-eureka-service注冊中心操作
3.1 pom.xml文件
<dependencies>
<!-- https://mvnrepository.com/artifact/org.springframework.cloud/spring-cloud-starter-eureka-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
</dependency>
</dependencies>
3.2 主啟動類
// 添加數(shù)據(jù)庫和 druid 卻未配置
// 則添加 exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class}
// 則啟動報錯
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class})
@EnableEurekaServer//告訴服務(wù)器我是一個注冊中心
public class EurekaServiceApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServiceApplication.class,args);
}
}
3.3 application.yml
server:
port: 8001
eureka:
instance:
hostname: 127.0.0.1 #eureka服務(wù)端的實例名字127.0.0.1 或 localhost
client:
#表識不向注冊中心注冊自己
register-with-eureka: false
#表示自己就是注冊中心,職責(zé)是維護(hù)服務(wù)實例,并不需要去檢索服務(wù)
fetch-registry: false
service-url:
#設(shè)置與eureka server交互的地址查詢服務(wù)和注冊服務(wù)都需要依賴這個地址
#服務(wù)注冊位置 http://127.0.0.1:8001/eureka/
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
4.對倉儲模塊cloud-stock-service操作
4.1 pom.xml
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
4.2 主啟動類
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class})
@EnableEurekaClient//需要使用Eureka注冊中心添加此注解
public class StockServiceApplication {
public static void main(String[] args) {
SpringApplication.run(StockServiceApplication.class,args);
}
}
4.3 application.yml
server:
port: 9001
spring:
application:
name: cloud-stock-service
eureka:
client:
# 向服務(wù)端注冊
register-with-eureka: true
# 需要檢索
fetchRegistry: true
service-url:
defaultZone: http://localhost:8001/eureka
4.4 StockController
@RestController
@RequestMapping("/stock")
public class StockController {
@GetMapping("/subStock")
public String subStock(){
System.out.println("庫存減1");
return "庫存減1";
}
}
5.對訂單模塊cloud-order-service操作
5.1 pom.xml文件
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
5.2 主啟動類
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class})
@EnableEurekaClient
public class OrderServiceApplication {
public static void main(String[] args) {
SpringApplication.run(OrderServiceApplication.class,args);
}
}
5.3 application.yml
server:
port: 7001
spring:
application:
name: cloud-order-servce
eureka:
client:
# 向服務(wù)端注冊
register-with-eureka: true
# 需要檢索
fetchRegistry: true
service-url:
defaultZone: http://localhost:8001/eureka/
5.4 OrderController
@RestController
@RequestMapping("/order")
public class OrderController {
//這里特別提醒 `http://` 千萬別忘加 本人因為這個錯誤找了很長時間 。。。。
//CLOUD-STOCK-SERVICE 這里是eureka注冊中心的名稱
private static final String HOST = "http://CLOUD-STOCK-SERVICE";
@Autowired
private RestTemplate restTemplate;
@GetMapping("/addOrder")
public String addOrder(){
System.out.println("訂單已完成");
return restTemplate.getForObject(HOST + "/stock/subStock",String.class);
}
}
5.5 RestTemplate配置類
@Configuration
public class ApplicationConfig {
@Bean
@LoadBalanced//負(fù)載均衡器
public RestTemplate restTemplate(){
return new RestTemplate();
}
}
6.啟動設(shè)置
我用的是idea 2021 ,多應(yīng)用啟動設(shè)置在如下位置

7.啟動
7.1 先啟動服務(wù)注冊中心cloud-eureka-service 訪問localhost:8001

7.2 在以端口號為9001和 9002 分別啟動 cloud-stock-service
在yml文件 server.port更改 啟動完成9001 更改端口號為9002 在啟動一次 再次訪問localhost:8001

7.3 在以端口號為7001和 7002 分別啟動 cloud-order-service ,和 7.2更改方式一樣 訪問 localhost:8001

8. **測試 **
8.1 訪問 localhost:7001/order/addOrder

8.2 觀察控制臺,當(dāng)我們多少刷新訪問 localhost:7001/order/addOrder 則會出現(xiàn)9001和9002交替處理請求(輪循),緩解服務(wù)器壓力,選擇服務(wù)規(guī)則和 @LoadBalanced 負(fù)載均衡器有關(guān)

試著訪問localhost:7002,結(jié)果相同
三、Eureka集群搭建
在微服務(wù)架構(gòu)中,一個系統(tǒng)往往由十幾甚至幾十個服務(wù)組成,若將這些服務(wù)全部注冊到同一個 Eureka Server 中,就極有可能導(dǎo)致 Eureka Server 因不堪重負(fù)而崩潰,最終導(dǎo)致整個系統(tǒng)癱瘓。解決這個問題最直接的辦法就是部署 Eureka Server 集群。
1.新建cloud-eureka-server-2和cloud-eureka-server-3

2.修改映射配置
打開 C:\Windows\System32\drivers\etc 目錄下的hosts文件 修改映射配置添加進(jìn)hosts文件

3.更改yml文件
3.1 cloud-eureka-service-2的yml文件
server:
port: 8002
eureka:
instance:
hostname: eureka8002.com #eureka服務(wù)端的實例名字
client:
#表識不向注冊中心注冊自己
register-with-eureka: false
#表示自己就是注冊中心,職責(zé)是維護(hù)服務(wù)實例,并不需要去檢索服務(wù)
fetch-registry: false
service-url:
#設(shè)置與eureka server交互的地址查詢服務(wù)和注冊服務(wù)都需要依賴這個地址
defaultZone: http://eureka8003.com:8003/eureka/
3.2 cloud-eureka-service-2的yml文件
server:
port: 8003
eureka:
instance:
hostname: eureka8003.com #eureka服務(wù)端的實例名字
client:
#表識不向注冊中心注冊自己
register-with-eureka: false
#表示自己就是注冊中心,職責(zé)是維護(hù)服務(wù)實例,并不需要去檢索服務(wù)
fetch-registry: false
service-url:
#設(shè)置與eureka server交互的地址查詢服務(wù)和注冊服務(wù)都需要依賴這個地址
defaultZone: http://eureka8002.com:8002/eureka/
3.3 cloud-order-service的yml文件
server:
port: 7001
spring:
application:
name: cloud-order-servce
eureka:
client:
# 向服務(wù)端注冊
register-with-eureka: true
# 需要檢索
fetchRegistry: true
service-url:
defaultZone: http://localhost:8002/eureka,http://localhost:8003/eureka
3.3 cloud-stock-service的yml文件
server:
port: 9001
spring:
application:
name: cloud-stock-service
eureka:
client:
# 向服務(wù)端注冊
register-with-eureka: true
# 需要檢索
fetchRegistry: true
service-url:
defaultZone: http://localhost:8002/eureka,http://localhost:8003/eureka
4.分別為cloud-eureka-service-2和cloud-eureka-service-3添加啟動類
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class})
@EnableEurekaServer//告訴服務(wù)器我是一個注冊中心
public class EurekaServiceApplication2 {
public static void main(String[] args) {
SpringApplication.run(EurekaServiceApplication2.class,args);
}
}
-----------------------------------------------------------------------------------------------------------------
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class})
@EnableEurekaServer//告訴服務(wù)器我是一個注冊中心
public class EurekaServiceApplication3 {
public static void main(String[] args) {
SpringApplication.run(EurekaServiceApplication3.class,args);
}
}
5.啟動
5.1 啟動cloud-eureka-service-2和cloud-eureka-service-3
5.1.1 訪問localhost:8002

5.1.2 訪問localhost:8003

5.2 啟動cloud-order-service和 端口號為9001和9002的cloud-stock-service集群服
5.2.1 訪問localhost:8002

5.2.2 訪問localhost:8003

6.測試 多次訪問localhost:7001 觀察控制臺

以上方式可以形成一組互相注冊的 Eureka Server 集群,當(dāng)服務(wù)提供者發(fā)送注冊請求到 Eureka Server 時,Eureka Server 會將請求轉(zhuǎn)發(fā)給集群中所有與之相連的 Eureka Server 上,以實現(xiàn) Eureka Server 之間的服務(wù)同步。

通過服務(wù)同步,服務(wù)消費者可以在集群中的任意一臺 Eureka Server 上獲取服務(wù)提供者提供的服務(wù)。這樣,即使集群中的某個服務(wù)注冊中心發(fā)生故障,服務(wù)消費者仍然可以從集群中的其他 Eureka Server 中獲取服務(wù)信息并調(diào)用,而不會導(dǎo)致系統(tǒng)的整體癱瘓,這就是 Eureka Server 集群的高可用性。
四、心跳續(xù)約
“心跳”指的是一段定時發(fā)送的自定義信息,讓對方知道自己“存活”,以確保連接的有效性。大部分 CS 架構(gòu)的應(yīng)用程序都采用了心跳機(jī)制,服務(wù)端和客戶端都可以發(fā)心跳。通常情況下是客戶端向服務(wù)器端發(fā)送心跳包,服務(wù)端用于判斷客戶端是否在線
心跳續(xù)約是指服務(wù)實例(Eureka客戶端)定期向Eureka服務(wù)器發(fā)送心跳包,以證明其仍然在線并愿意繼續(xù)提供服務(wù)。Eureka服務(wù)器會根據(jù)這些心跳包來更新服務(wù)實例的活躍狀態(tài),并維護(hù)一個可用的服務(wù)實例列表。

功能介紹
- Spring Cloud A 和 Spring Cloud B可以看作兩個服務(wù)的提供者
- Spring Cloud C 相當(dāng)于 服務(wù)的消費者 定時(默認(rèn)30秒)獲取服務(wù)列表
- registry服務(wù)注冊列表 里面存儲的是 各個注冊服務(wù)的 名稱 ip 端口號
- readWriteCacheMap 會實時同步registry注冊列表中的數(shù)據(jù)
- readOnlyCacheMap 默認(rèn)每30秒去同步一次readWriterCacheMap對象中的數(shù)據(jù)
詳細(xì)流程
- A和B 服務(wù) 向Eureka Service 服務(wù)注冊列表中注冊服務(wù) 將自己的服務(wù)名稱 ip + 端口號注冊到 registry服務(wù)注冊列表。
- A和B每隔30秒 (默認(rèn)30秒) 發(fā)送 一次心跳任務(wù)告訴Eureka 我還活著, registry服務(wù)注冊列表 同步數(shù)據(jù)到readWriteCacheMap
- C 服務(wù) 通過readOnlyCacheMap 每30秒拉去一次注冊表數(shù)據(jù),這個數(shù)據(jù)不是同步的而是30秒(默認(rèn)30秒)更新一次,這也是有時我們會在UI界面上看到服務(wù)注冊成功,調(diào)用時卻出現(xiàn)錯誤的原因。同理,服務(wù)下線也存在同樣的問題,服務(wù)已經(jīng)下線了,但是還是有客戶端在調(diào)用已經(jīng)下線的服務(wù),這時就會出現(xiàn)連接拒絕的錯誤。
- 我們在Eureka UI頁面上看到的注冊信息,實際上并沒有走readOnlyCacheMap,而是直接通過registry服務(wù)注冊列表獲取,所以我們能夠在Eureka UI頁面實時的看到注冊的新服務(wù)。
- 服務(wù)續(xù)約默認(rèn)是30秒 ,定時請理60秒清理一次超過90秒未續(xù)約的服務(wù),也就是說在連續(xù)3次丟失心跳后會被Eureka Server的evict線程清理,最極端的情況,服務(wù)下線后,可能需要延遲180s之后,Eureka Server中的registry對象才會被更新。
綜上分析,在非手動清除的情況下,緩存需要180秒才能感知下線的服務(wù),這種情況在生產(chǎn)環(huán)境中非常嚴(yán)重。
上述問題中,我們可以更改默認(rèn)值,來解決感知下線服務(wù)時間過長問題
Eureka注冊中心
eureka:
server:
#清理無效服務(wù)間隔 (默認(rèn)60秒)
eviction-interval-timer-in-ms: 1000
#同步readWrite到readOnly間隔(默認(rèn)30秒)
response-cache-update-interval-ms: 10000
#Client直接從readWriteCacheMap更新服
#use-read-only-response-cache: false
服務(wù)提供者
eureka:
instance:
# Eureka注冊中心(服務(wù)端)在收到客戶端心跳之后,
#等待下一次心跳的超時時間,如果在這個時間內(nèi)沒有收到下次心跳,則移除該客戶端。(默認(rèn)90秒)
lease-expiration-duration-in-seconds: 5
# 客戶端向注冊中心發(fā)送心跳的時間間隔(默認(rèn)30秒)
lease-renewal-interval-in-seconds: 2
五、Eureka自我保護(hù)機(jī)制
Eureka的自我保護(hù)機(jī)制是一種應(yīng)對網(wǎng)絡(luò)異常的安全保護(hù)措施,寧可同時保留所有微服務(wù)(健康的服務(wù)和不健康的服務(wù)都會保留)也不盲目移除任何健康的服務(wù)。
當(dāng)我們在本地調(diào)試基于 Eureka 的程序時,Eureka 服務(wù)注冊中心很有可能會出現(xiàn)紅色警告。

- 實際上,這個警告是觸發(fā)了 Eureka 的自我保護(hù)機(jī)制而出現(xiàn)的。默認(rèn)情況下,如果 Eureka Server 在一段時間內(nèi)沒有接收到某個服務(wù)提供者的心跳,就會將這個服務(wù)提供者提供的服務(wù)從服務(wù)注冊表中移除。 這樣服務(wù)消費者就再也無法從服務(wù)注冊中心中獲取到這個服務(wù)了,更無法調(diào)用該服務(wù)。
- 但在實際的分布式微服務(wù)系統(tǒng)中,健康的服務(wù)也有可能會由于網(wǎng)絡(luò)故障(例如網(wǎng)絡(luò)延遲、卡頓等原因)而無法與 Eureka Server正常通訊。若此時 Eureka Server因為沒有接收心跳而誤將健康的服務(wù)從服務(wù)列表中移除,這顯然是不合理的。而 Eureka 的自我保護(hù)機(jī)制就是來解決此問題的。
- 所謂 “Eureka 的自我保護(hù)機(jī)制”,其中心思想就是“好死不如賴活著”。如果 Eureka Server 在一段時間內(nèi)沒有接收到 Eureka Client 的心跳,那么 Eureka Server 就會開啟自我保護(hù)模式,將所有的 Eureka Client 的注冊信息保護(hù)起來,而不是直接從服務(wù)注冊表中移除。一旦網(wǎng)絡(luò)恢復(fù),這些 Eureka Client 提供的服務(wù)還可以繼續(xù)被服務(wù)消費者消費。
默認(rèn)情況下,Eureka 的自我保護(hù)機(jī)制是開啟的,如果想要關(guān)閉,則需要在配置文件中添加以下配置
eureka:
server:
# false 關(guān)閉 Eureka 的自我保護(hù)機(jī)制,默認(rèn)是開啟
enable-self-preservation: false
需要注意的是:
Eureka 的自我保護(hù)機(jī)制也存在弊端。如果在 Eureka 自我保護(hù)機(jī)制觸發(fā)期間,服務(wù)提供者提供的服務(wù)出現(xiàn)問題,那么服務(wù)消費者就很容易獲取到已經(jīng)不存在的服務(wù)進(jìn)而出現(xiàn)調(diào)用失敗的情況。此時,我們可以通過客戶端的容錯機(jī)制來解決此問題。
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
- SpringCloud_Eureka服務(wù)注冊與發(fā)現(xiàn)基礎(chǔ)及構(gòu)建步驟
- SpringCloud?Eureka服務(wù)治理之服務(wù)注冊服務(wù)發(fā)現(xiàn)
- SpringCloud服務(wù)注冊和發(fā)現(xiàn)組件Eureka
- SpringCloud實現(xiàn)Eureka服務(wù)注冊與發(fā)現(xiàn)
- SpringCloud Eureka實現(xiàn)服務(wù)注冊與發(fā)現(xiàn)
- SpringCloud之服務(wù)注冊與發(fā)現(xiàn)Spring Cloud Eureka實例代碼
- springcloud干貨之服務(wù)注冊與發(fā)現(xiàn)(Eureka)
相關(guān)文章
Java動態(tài)顯示文件上傳進(jìn)度實現(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了Java動態(tài)顯示文件上傳進(jìn)度實現(xiàn)代碼,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-01-01
使用spring-data-jpa實現(xiàn)簡單的兩表聯(lián)查實踐
本文介紹了Spring Data JPA在Spring Boot中的配置與簡單操作,涵蓋一對多和多對一關(guān)系的處理,適合初學(xué)者學(xué)習(xí),通過配置數(shù)據(jù)源、創(chuàng)建實體類和DAO接口,實現(xiàn)基本的CRUD操作,并提供了一個簡單的示例2026-06-06
Cursor IDE中SpringBoot項目啟動內(nèi)存不足問題的解決方案
在CursorIDE中運行SpringBoot項目時,可能出現(xiàn)啟動失敗、報錯等問題,這些問題通常與JVM內(nèi)存設(shè)置不當(dāng)有關(guān),本文總結(jié)了多種解決方案,需要的朋友可以參考下2026-04-04
IDEA2020.3.2版本自動注釋類和方法注釋模板配置步驟詳解
這篇文章主要介紹了IDEA2020.3.2版本自動注釋類和方法注釋模板配置步驟,本文給大家分享了我自己創(chuàng)建過程通過圖文并茂的形式給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2021-03-03
數(shù)據(jù)定位在java購物車系統(tǒng)中的應(yīng)用
實現(xiàn)"加入購物車"功能,數(shù)據(jù)定位至關(guān)重要,它通過用戶ID和商品ID等標(biāo)識符實現(xiàn)快速查詢和數(shù)據(jù)一致性,主鍵、外鍵和聯(lián)合索引等數(shù)據(jù)庫技術(shù),以及Redis緩存和并發(fā)控制策略如樂觀鎖或分布式鎖,共同保障了購物車系統(tǒng)的查詢效率和數(shù)據(jù)安全,這些機(jī)制對高并發(fā)和大數(shù)據(jù)量的場景尤為重要2024-10-10
SpringBoot Shiro 權(quán)限注解不起作用的解決方法
本文主要介紹了SpringBoot Shiro 權(quán)限注解不起作用的解決方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下2021-07-07
Java Swing中的表格(JTable)和樹(JTree)組件使用實例
這篇文章主要介紹了Java Swing中的表格(JTable)和樹(JTree)組件使用實例,本文同時講解了表格和樹的基本概念、常用方法、代碼實例,需要的朋友可以參考下2014-10-10

