Spring框架的事務管理

引言

在企業級應用開發中,事務管理是一個至關重要的環節,它確保了數據的一致性和完整性。Spring 框架為我們提供了強大而靈活的事務管理功能,能夠幫助開發者更輕松地處理復雜的事務場景。本文將深入探討 Spring 框架的事務管理,包括相關的類和 API,以及聲明式事務管理的實現方式,并結合具體代碼示例進行詳細解釋。

1. Spring 框架的事務管理相關的類和 API

1.1 PlatformTransactionManager 接口

PlatformTransactionManager?是 Spring 框架中用于管理事務的核心接口,它定義了事務的基本操作,如提交和回滾。該接口有具體的實現類,我們需要根據不同的持久層框架選擇合適的實現類。

接口方法
  • void commit(TransactionStatus status):用于提交事務。
  • void rollback(TransactionStatus status):用于回滾事務。
實現類選擇
  • DataSourceTransactionManager:如果使用 Spring 的 JDBC 模板或者 MyBatis 框架,應選擇這個實現類。因為這些框架都是基于數據源(DataSource)進行數據庫操作的,DataSourceTransactionManager?可以很好地與數據源集成,管理事務。
  • HibernateTransactionManager:當使用 Hibernate 框架時,需要選擇這個實現類。它專門為 Hibernate 的事務管理而設計,能夠與 Hibernate 的會話(Session)和事務機制無縫對接。

1.2 TransactionDefinition 接口

TransactionDefinition?接口定義了事務的一些基本屬性,包括事務隔離級別和事務傳播行為。

事務隔離級別

事務隔離級別用于控制多個事務之間的可見性和并發訪問。常見的隔離級別有:

  • ISOLATION_DEFAULT:使用數據庫的默認隔離級別。
  • ISOLATION_READ_UNCOMMITTED:允許讀取未提交的數據,可能會導致臟讀、不可重復讀和幻讀問題。
  • ISOLATION_READ_COMMITTED:只能讀取已提交的數據,避免了臟讀,但仍可能出現不可重復讀和幻讀。
  • ISOLATION_REPEATABLE_READ:保證在同一個事務中多次讀取同一數據的結果是一致的,避免了臟讀和不可重復讀,但仍可能出現幻讀。
  • ISOLATION_SERIALIZABLE:最高的隔離級別,所有事務依次執行,避免了臟讀、不可重復讀和幻讀,但會降低并發性能。

事務傳播行為

事務傳播行為定義了在一個事務方法調用另一個事務方法時,事務應該如何處理。常見的傳播行為有:

  • PROPAGATION_REQUIRED:如果當前存在事務,則加入該事務;如果不存在,則創建一個新的事務。
  • PROPAGATION_SUPPORTS:如果當前存在事務,則加入該事務;如果不存在,則以非事務方式執行。
  • PROPAGATION_MANDATORY:如果當前存在事務,則加入該事務;如果不存在,則拋出異常。
  • PROPAGATION_REQUIRES_NEW:無論當前是否存在事務,都創建一個新的事務,并掛起當前事務。
  • PROPAGATION_NOT_SUPPORTED:以非事務方式執行,如果當前存在事務,則掛起該事務。
  • PROPAGATION_NEVER:以非事務方式執行,如果當前存在事務,則拋出異常。
  • PROPAGATION_NESTED:如果當前存在事務,則在嵌套事務中執行;如果不存在,則創建一個新的事務。

?2. Spring 框架聲明式事務管理

2.1、XML 配置方式

1. 配置文件

  • jdbc.properties:存儲數據庫連接信息,包括驅動類名、URL、用戶名和密碼。
jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/spring_db?useSSL=false&characterEncoding=utf8
jdbc.username=root
jdbc.password=root
  • applicationContext.xml:核心配置文件,主要完成以下配置:
    • 加載屬性文件:通過?<context:property - placeholder>?加載?jdbc.properties
    • 配置數據源:使用 Druid 數據源,將屬性文件中的配置注入。
    • 配置平臺事務管理器:使用?DataSourceTransactionManager,并關聯數據源。
    • 配置事務通知:通過?<tx:advice>?定義事務屬性,如?pay?方法使用事務,find*?方法只讀。
    • 配置 AOP:通過?<aop:config>?定義切入點和通知的關聯。
    • 配置 Service 和 Dao:將 Service 和 Dao 作為 Bean 注冊到 Spring 容器中,并進行依賴注入。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 加載屬性文件 --><context:property-placeholder location="classpath:jdbc.properties"/><!-- 配置數據源 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driverClassName}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></bean><!-- 配置平臺事務管理器 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean><!-- 配置事務通知 --><tx:advice id="txAdvice" transaction-manager="transactionManager"><tx:attributes><!-- pay 方法使用事務 --><tx:method name="pay" isolation="DEFAULT" propagation="REQUIRED"/><!-- find 開頭的方法只讀 --><tx:method name="find*" read-only="true"/></tx:attributes></tx:advice><!-- 配置 AOP --><aop:config><aop:advisor advice-ref="txAdvice" pointcut="execution(public * com.qcbyjy.demo4.AccountServiceImpl.pay(..))"/></aop:config><!-- 配置 Service --><bean id="accountService" class="com.qcbyjy.demo1.AccountServiceImpl"><property name="accountDao" ref="accountDao"/></bean><!-- 配置 Dao --><bean id="accountDao" class="com.qcbyjy.demo1.AccountDaoImpl"><property name="dataSource" ref="dataSource"/></bean>
</beans>

2.Java類?

  • AccountDao.java:定義數據訪問接口,包含?outMoneyinMoney?和?findMoney?方法。
package com.qcbyjy.demo1;public interface AccountDao {void outMoney(String out, double money);void inMoney(String in, double money);double findMoney(String name);
}
  • AccountDaoImpl.java:實現?AccountDao?接口,通過?JdbcDaoSupport?進行數據庫操作。
package com.qcbyjy.demo1;import org.springframework.jdbc.core.support.JdbcDaoSupport;public class AccountDaoImpl extends JdbcDaoSupport implements AccountDao {@Overridepublic void outMoney(String out, double money) {String sql = "update account set money=money-? where name=?";this.getJdbcTemplate().update(sql, money, out);}@Overridepublic void inMoney(String in, double money) {String sql = "update account set money=money+? where name=?";this.getJdbcTemplate().update(sql, money, in);}@Overridepublic double findMoney(String name) {String sql = "select money from account where name=?";return this.getJdbcTemplate().queryForObject(sql, Double.class, name);}
}
  • AccountService.java:定義業務服務接口,包含?pay?和?checkBalance?方法。
package com.qcbyjy.demo1;public interface AccountService {void pay(String out, String in, double money);double checkBalance(String name);
}
  • AccountServiceImpl.java:實現?AccountService?接口,調用?AccountDao?完成業務邏輯。
package com.qcbyjy.demo1;public class AccountServiceImpl implements AccountService {private AccountDao accountDao;public void setAccountDao(AccountDao accountDao) {this.accountDao = accountDao;}@Overridepublic void pay(String out, String in, double money) {accountDao.outMoney(out, money);// 模擬異常,測試事務回滾// int a = 1/0;accountDao.inMoney(in, money);}@Overridepublic double checkBalance(String name) {return accountDao.findMoney(name);}
}

3.測試?

package com.qcbyjy.test.demo1;import com.qcbyjy.demo1.AccountService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class Demo1 {@Testpublic void testXmlTransaction(){ApplicationContext context =new ClassPathXmlApplicationContext("applicationContext.xml");AccountService accountService =(AccountService) context.getBean("accountService");System.out.println("XML配置方式事務測試...");try {accountService.pay("aaa", "ccc", 100);System.out.println("轉賬成功!");} catch (Exception e) {System.out.println("轉賬失敗,事務已回滾:" + e.getMessage());}}
}

4. 重要知識點

  • 事務通知和 AOP 配置:通過?<tx:advice>?定義事務屬性,再通過?<aop:config>?將事務通知應用到指定的切入點,實現事務的織入。
  • 屬性占位符<context:property - placeholder>?可以方便地加載屬性文件,將配置信息從 XML 文件中分離出來,提高配置的可維護性。

2.2、XML + 注解方式

1. 配置文件

  • applicationContext_1.xml:主要完成以下配置:
    • 開啟注解掃描:通過?<context:component - scan>?掃描指定包下的注解組件。
    • 加載屬性文件:同 XML 配置方式。
    • 配置數據源和事務管理器:同 XML 配置方式。
    • 配置 Jdbc 模板:為 Dao 層提供數據庫操作模板。
    • 開啟事務注解支持:通過?<tx:annotation - driven>?開啟?@Transactional?注解的支持。
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsd"><!-- 開啟注解掃描 --><context:component-scan base-package="com.qcbyjy.demo2"/><!-- 加載屬性文件 --><context:property-placeholder location="classpath:db.properties"/><!-- 配置數據源 --><bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"><property name="driverClassName" value="${jdbc.driverClassName}"/><property name="url" value="${jdbc.url}"/><property name="username" value="${jdbc.username}"/><property name="password" value="${jdbc.password}"/></bean><!-- 配置平臺事務管理器 --><bean id="transactionManager"class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"/></bean><!-- 配置Jdbc模板 --><bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate"><property name="dataSource" ref="dataSource"/></bean><!-- 開啟事務注解支持 --><tx:annotation-driven transaction-manager="transactionManager"/>
</beans>

2. Java 類

  • AccountDao.java:同 XML 配置方式。
  • AccountDaoImpl.java:使用?@Repository?注解將該類注冊為 Spring Bean,并通過?@Autowired?注入?JdbcTemplate
package com.qcbyjy.demo2;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;@Repository
public class AccountDaoImpl  implements AccountDao {@Autowiredprivate JdbcTemplate jdbcTemplate;/***付款*@paramout*@parammoney*/public void outMoney(String out,double money){String sql="update account set money=money - ? where name = ?";jdbcTemplate.update(sql,money,out);}/***收款*@paramin*@parammoney*/public void inMoney(String in,double money){String sql="update account set money=money +? where name= ?";jdbcTemplate.update(sql,money,in);}}
  • AccountService.java:同 XML 配置方式。
  • AccountServiceImpl.java:使用?@Service?注解將該類注冊為 Spring Bean,并使用?@Transactional?注解定義事務屬性。
package com.qcbyjy.demo2;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;@Service
@Transactional(isolation = Isolation.DEFAULT)
public class AccountServiceImpl implements AccountService {@Autowiredprivate AccountDao accountDao;/***轉賬方法*@paramout付款人*@paramin收款人*@parammoney金額*/public void pay(String out,String in,double money){accountDao.outMoney(out,money);// 模擬異常
//         int a = 1/0;accountDao.inMoney(in,money);}}

3.測試

package com.qcbyjy.test.demo2;import com.qcbyjy.demo2.AccountService;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class Demo2 {@Testpublic void testAnnotationTransaction(){ApplicationContext context=new ClassPathXmlApplicationContext("applicationContext_1.xml");AccountService accountService=context.getBean(AccountService.class);System.out.println("XML+注解方式事務測試...");try {accountService.pay("ccc", "aaa", 100);System.out.println("轉賬成功!");} catch (Exception e) {System.out.println("轉賬失敗,事務已回滾:" + e.getMessage());}}
}

4. 重要知識點

  • 注解掃描<context:component - scan>?可以自動掃描指定包下的?@Component@Repository@Service?和?@Controller?注解的類,并將它們注冊為 Spring Bean。
  • @Transactional?注解:用于定義事務屬性,如隔離級別、傳播行為、是否只讀等。可以應用在類或方法上,應用在類上時,該類的所有公共方法都將應用該事務屬性。

?2.3、純注解方式

1. Java 配置類

  • SpringConfig.java:使用?@Configuration?注解將該類標記為配置類,通過?@ComponentScan?掃描指定包下的注解組件,使用?@EnableTransactionManagement?開啟事務注解支持,并通過?@Bean?方法定義數據源、Jdbc 模板和事務管理器。
package com.qcbyjy.demo3;import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;import javax.annotation.Resource;
import javax.sql.DataSource;@Configuration
@ComponentScan(basePackages = "com.qcbyjy.demo3")
@EnableTransactionManagement
public class SpringConfig {@Bean(name="dataSource")public DataSource dataSource() {// 創建連接池對象,Spring框架內置了連接池對象DruidDataSource dataSource = new DruidDataSource();// 設置4個參數dataSource.setDriverClassName("com.mysql.jdbc.Driver");dataSource.setUrl("jdbc:mysql://localhost:3306/spring_db?useSSL=false&characterEncoding=utf8");dataSource.setUsername("root");dataSource.setPassword("12345");return dataSource;}@Resource(name="dataSource")@Bean(name="jdbcTemplate")public JdbcTemplate createJdbcTemplate(DataSource dataSource){JdbcTemplate template =new JdbcTemplate(dataSource);return template;}@Resource(name="dataSource")@Bean(name="transactionManager")public PlatformTransactionManager createTransactionManager(DataSource dataSource) {DataSourceTransactionManager manager = new DataSourceTransactionManager(dataSource);return manager;}//    @Bean
//    public JdbcTemplate jdbcTemplate(DataSource dataSource) {
//        return new JdbcTemplate(dataSource);
//    }//    @Bean
//    public PlatformTransactionManager transactionManager(DataSource dataSource) {
//        return new DataSourceTransactionManager(dataSource);
//    }
}

2. Java 類

  • AccountDao.javaAccountDaoImpl.javaAccountService.java?和?AccountServiceImpl.java:同 XML + 注解方式。

3.測試

package com.qcbyjy.test.Demo3;import com.qcbyjy.demo3.AccountService;
import com.qcbyjy.demo3.SpringConfig;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class Demo3 {@Testpublic void testPureAnnotationTransaction() {AnnotationConfigApplicationContext context=new AnnotationConfigApplicationContext(SpringConfig.class);AccountService accountService=context.getBean(AccountService.class);System.out.println("純注解方式事務測試...");try {accountService.pay("aaa", "ccc", 1000);System.out.println("轉賬成功!");} catch (Exception e) {System.out.println("轉賬失敗,事務已回滾:" + e.getMessage());}context.close();}
}

4. 重要知識點

  • Java 配置類:使用?@Configuration?注解的類可以替代 XML 配置文件,通過?@Bean?方法定義 Bean,提高配置的靈活性和可維護性。
  • @EnableTransactionManagement:開啟 Spring 的事務注解支持,使得?@Transactional?注解生效。

4.事務特性驗證

三種方式都可以通過取消注釋模擬異常的代碼(int a = 1/0;)來測試事務回滾功能。每次測試前后會打印賬戶余額,驗證事務是否正常工作。同時,需要創建?spring_db?數據庫和?account?表,并初始化張三和李四的賬戶余額為 1000。

5.總結

  • XML 配置方式:適合于對配置細節有嚴格要求,且團隊對 XML 配置比較熟悉的場景。通過 XML 可以清晰地定義事務的各個方面,但配置文件可能會變得冗長和復雜。
  • XML + 注解方式:結合了 XML 配置的靈活性和注解的簡潔性,XML 負責全局配置,注解負責局部配置,是一種比較常用的方式。
  • 純注解方式:適合于追求代碼簡潔性和開發效率的場景,完全基于 Java 配置和注解,減少了 XML 配置文件的使用,但對開發者的 Java 配置能力要求較高。

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/pingmian/80940.shtml
繁體地址,請注明出處:http://hk.pswp.cn/pingmian/80940.shtml
英文地址,請注明出處:http://en.pswp.cn/pingmian/80940.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

FPGA: UltraScale+ bitslip實現(ISERDESE3)

收獲 一晃五年~ 五年前那個夏夜&#xff0c;我對著泛藍的屏幕敲下《給十年后的自己》&#xff0c;在2020年的疫情迷霧中編織著對未來的想象。此刻回望&#xff0c;第四屆集創賽的參賽編號仍清晰如昨&#xff0c;而那個在家熬夜焊電路板的"不眠者"&#xff0c;現在…

用 wireshark 解密 SIP over TLS 以及 SRTP 解密

--todo 有空再搞 MicroSIP 向 FreeSWITCH 注冊&#xff0c;transport 設置為 tls 同時 Media Encryption 設置為強制 FreeSWITCH 做一個這樣的路由&#xff1a; <action application"set" data"rtp_secure_mediaoptional"/> <action applicat…

Delphi 12.3調用Chrome/edge內核實現DEMO源碼

DELPHI使用調用Chrome/Edge內核瀏覽器&#xff0c;雖然舊的WebBrowser也還可以用&#xff0c;但大勢所趨&#xff0c;新版的已經不需要使用第三方的組件了&#xff0c;算是全內置的開發了&#xff0c;不廢話 Unit1 源碼 Form 源碼 unit Unit1;interfaceusesWinapi.Windows, W…

快速搭建一個electron-vite項目

1. 初始化項目 在命令行中運行以下命令 npm create quick-start/electronlatest也可以通過附加命令行選項直接指定項目名稱和你想要使用的模版。例如&#xff0c;要構建一個 Electron Vue 項目&#xff0c;運行: # npm 7&#xff0c;需要添加額外的 --&#xff1a; npm cre…

26考研 | 王道 | 計算機組成原理 | 一、計算機系統概述

26考研 | 王道 | 計算機組成原理 | 一、計算機系統概述 文章目錄 26考研 | 王道 | 計算機組成原理 | 一、計算機系統概述1.1 計算機的發展1.2 計算機硬件和軟件1.2.1 計算機硬件的基本組成1.2.2 各個硬件的工作原理1.2.3 計算機軟件1.2.4 計算機系統的層次結構1.2.5 計算機系統…

01-數據結構概述和時間空間復雜度

數據結構概述和時間空間復雜度 1. 什么是數據結構 數據結構&#xff08;Data Structure&#xff09;是計算機存儲、組織數據的方式&#xff0c;指相互之間存在一種或多種特定關系的數據元素的集合。 2. 什么是算法 算法&#xff08;Algorithm&#xff09;就是定義良好的計算…

大數據架構選型全景指南:核心架構對比與實戰案例 解析

目錄 大數據架構選型全景指南&#xff1a;核心架構對比與實戰案例解析1. 主流架構全景概覽1.1 核心架構類型1.2 關鍵選型維度 2. 架構對比與選型矩陣2.1 主流架構對比表2.2 選型決策樹 3. 案例分析與實現案例1&#xff1a;電商實時推薦系統&#xff08;Lambda架構&#xff09;案…

(51單片機)LCD顯示紅外遙控相關數字(Delay延時函數)(LCD1602教程)(Int0和Timer0外部中斷教程)(IR紅外遙控模塊教程)

前言&#xff1a; 本次Timer0模塊改裝了一下&#xff0c;注意&#xff01;&#xff01;&#xff01;今天只是簡單的實現一下&#xff0c;明天用次功能顯示遙控密碼鎖 演示視頻&#xff1a; 在審核 源代碼&#xff1a; 如上圖將9個文放在Keli5 中即可&#xff0c;然后燒錄在…

網絡實驗-防火墻雙機熱備份

實驗目的 了解防火墻雙機熱備份配置&#xff0c;提供部署防火墻可靠性。 網絡拓撲 左側為trust域&#xff0c;右側為untrust域。防火墻之間配置雙機熱備份。 配置內容 master VRRP 由于防火墻是基于會話表匹配回程流量&#xff0c;流量去向和回程必須通過同一個防火墻。…

【2025最新】VSCode Cline插件配置教程:免費使用Claude 3.7提升編程效率

 ?2025年最新VSCode Cline插件安裝配置教程&#xff0c;詳解多種免費使用Claude 3.7的方法&#xff0c;集成DeepSeek-R1與5大實用功能&#xff0c;專業編程效率提升指南。 Cline是VSCode中功能最強大的AI編程助手插件之一&#xff0c;它能與Claude、OpenAI等多種大模型無縫集…

考研英一真題學習筆記 2018年

2018 年全國碩士研究生招生考試 英語 &#xff08;科目代碼&#xff1a;201&#xff09; Section Ⅰ Use of English Directions: Read the following text. Choose the best word(s) for each numbered blank and mark A, B, C or D on the ANSWER SHEET. (10 points) Trust i…

華碩服務器-品類介紹

目錄 一、核心產品線解析 1. 機架式服務器 2. 塔式服務器 3. 高密度計算服務器 二、關鍵技術與模組配置 1. 主板與管理模塊 2. 電源與散熱 3. 存儲與網絡 三、應用場景與行業解決方案 1. 人工智能與高性能計算 2. 云計算與虛擬化 3. 邊緣計算與工業物聯網 一、核心…

硅基計劃2.0 學習總結 貳

一、程序邏輯控制&#xff08;順序、選擇&循環&#xff09; 順序結構就不多介紹了&#xff0c;就是各個語句按照先后順序進行執行 &#xff08;1&#xff09;選擇結構 三大選擇類型&#xff1a;if、if-else、if-else if-else以及懸浮else的問題 基本已經在之前在C語言文章…

RabbitMQ最新入門教程

文章目錄 RabbitMQ最新入門教程1.什么是消息隊列2.為什么使用消息隊列3.消息隊列協議4.安裝Erlang5.安裝RabbitMQ6.RabbitMQ核心模塊7.RabbitMQ六大模式7.1 簡單模式7.2 工作模式7.3 發布訂閱模式7.4 路由模式7.5 主題模式7.6 RPC模式 8.RabbitMQ四種交換機8.1 直連交換機8.2 主…

工具學習_VirusTotal使用

VirusTotal Intelligence 允許用戶在其龐大的數據集中進行搜索&#xff0c;以查找符合特定條件的文件&#xff0c;例如哈希值、殺毒引擎檢測結果、元數據信息、提交時的文件名、文件結構特征、文件大小等。可以說&#xff0c;它幾乎是惡意軟件領域的“谷歌搜索引擎”。 網頁使…

計算機系統----軟考中級軟件設計師(自用學習筆記)

目錄 1、計算機的基本硬件系統 2、CPU的功能 3、運算器的組成 4、控制器 5、計算機的基本單位 6、進制轉換問題 7、原碼、反碼、補碼、移碼 8、浮點數 9、尋址方式 10、奇偶校驗碼 11、海明碼 12、循環冗余校驗碼 13、RISC和CISC 14、指令的處理方式 15、存儲器…

揚州卓韻酒店用品:優質洗浴用品,提升酒店滿意度與品牌形象

在酒店提供的服務里&#xff0c;沐浴用品占據了非常重要的地位&#xff0c;其質量與種類直接關系到客人洗澡時的感受。好的沐浴用品能讓客人洗澡時感到舒心和快樂&#xff0c;反之&#xff0c;質量不好的用品可能會影響客人整個住宿期間的愉悅心情。挑選恰當的洗浴用品不僅能夠…

學習筆記:黑馬程序員JavaWeb開發教程(2025.4.5)

12.4 登錄認證-登錄校驗-會話跟蹤方案一 設置cookie&#xff0c;服務器給瀏覽器響應數據&#xff0c;通過control方法形參當中獲取response&#xff0c;調用response當中的addCookie方法實現 獲取cookie&#xff0c;調用getCookie方法 用戶可以通過瀏覽器設置禁用cookie 跨域…

進程替換講解

1. 基本概念 1.1 進程替換 vs. 進程創建 進程創建&#xff1a;使用fork()或clone()等系統調用創建一個新的子進程&#xff0c;子進程是父進程的副本&#xff0c;擁有相同的代碼和數據。進程替換&#xff1a;使用exec系列函數在當前進程中加載并執行一個新的程序&#xff0c;替…

【微服務】SpringBoot + Docker 實現微服務容器多節點負載均衡詳解

目錄 一、前言 二、前置準備 2.1 基本環境 2.2 準備一個springboot工程 2.2.1 準備幾個測試接口 2.3 準備Dockerfile文件 2.4 打包上傳到服務器 三、制作微服務鏡像與運行服務鏡像 3.1 拷貝Dockerfile文件到服務器 3.2 制作服務鏡像 3.3 啟動鏡像服務 3.4 訪問一下服…