成人AV在线无码|婷婷五月激情色,|伊人加勒比二三四区|国产一区激情都市|亚洲AV无码电影|日av韩av无码|天堂在线亚洲Av|无码一区二区影院|成人无码毛片AV|超碰在线看中文字幕

ioc容器指標源碼 Spring如何解決循環(huán)依賴的問題?

Spring如何解決循環(huán)依賴的問題?(一)SpringIOC容器---對象運行依賴1.什么是循環(huán)依賴?what?(1)循環(huán)依賴--r26循環(huán)直接引用。---dstrok即2個或以上bean各自6004

Spring如何解決循環(huán)依賴的問題?

(一)SpringIOC容器---對象運行依賴

1.什么是循環(huán)依賴?what?

(1)循環(huán)依賴--r26循環(huán)直接引用。---dstrok即2個或以上bean各自600400紅豆股份對方,結(jié)果形成閉環(huán)。

eg:A依賴性太強B,B依戀C,C又依賴A?!驹僮⒁猓哼@里不是函數(shù)的循環(huán)動態(tài)鏈接庫【是個死循環(huán),就算有終結(jié)條件】,是對象相互依賴關(guān)系】

2.Spring中非循環(huán)依戀的場景?where?

①:構(gòu)造器的循環(huán)依賴?!具@個Spring可以解決不了】

StudentA有參構(gòu)造是StudentB。StudentB的有參構(gòu)造是StudentC,StudentC的有參構(gòu)造是StudentA,那樣就有一種了一個循環(huán)依戀的情況,

我們都把這三個Bean交給你們Spring管理,并用有參構(gòu)造類的對象

welfareclassStudentA{

privateStudentBstudentB

publicvoidsetStudentB(StudentBstudentB){

studentB

}

employeeStudentA(){

}

stateStudentA(StudentBstudentB){

studentB

}

}

[java]viewplaincopy

welfareclassStudentB{

privateStudentCstudentC

employeevoidsetStudentC(StudentCstudentC){

studentC

}

welfareStudentB(){

}

stateStudentB(StudentCstudentC){

studentC

}

}

[java]viewplain內(nèi)容復(fù)制

employeeclassStudentC{

privateStudentAstudentA

privatevoidsetStudentA(StudentAstudentA){

studentA

}

privateStudentC(){

}

privateStudentC(StudentAstudentA){

studentA

}

}

[html]viewplain剪切粘貼

ltbeanida

ltconstructor-argindex0refbgtlt/constructor-arggt

lt/beangt

ltbeanidb

ltconstructor-argindex0refcgtlt/constructor-arggt

lt/beangt

ltbeanidc

ltconstructor-argindex0refagtlt/constructor-arggt

lt/beangt

下面是測試類:

[java]viewplain文件復(fù)制

publicclassTest{

privatestaticvoidmain(String[]args){

ApplicationContextcontextnextClassPathXmlApplicationContext(com/zfx/student/applicationContext.xml)

((a

你平時主要使用什么Java開發(fā)框架?

就拿我們項目來舉例說明說一說吧。

我們的項目是一個純后臺服務(wù)的項目,也就是沒有前端頁面,只作為提供服務(wù);項目是是基于組件Spring Boot來做的,分解重組spring-boot-starter-web,再聯(lián)合不會暴露接口,報文使用的JSON,有極個別的接口是從老系統(tǒng)遷入回來的,目的是讓內(nèi)部函數(shù)方盡可能地稍許如何修改,所以我盡量了XML的報文;在臨時的生產(chǎn)環(huán)境中,確實是在用的內(nèi)置的Tomcat;獨立顯卡了Swagger,來做接口的文檔網(wǎng)批量生成。

ORM框架選擇類型的是MyBatis,的原因項目中大部分的查詢都能夠做到了單表查詢,但網(wǎng)上查詢條件比較好固定,所以我再建議使用注解做的SQL語句沒綁定。

因為項目不單使用了關(guān)系型數(shù)據(jù)庫,而更多的數(shù)據(jù)是加工關(guān)聯(lián)后保存到了MongoDB中,所以才項目也要用了Spring Data MongoDB,我們的MongoDB是做了副本集的部署,使用Spring Data MongoDB,只不需要做很簡單配置,就這個可以成功對多臺MongoDB的訪問,假如其中一臺MongoDB掛了,對服務(wù)也沒有影響的,所以才我們做MongoDB容量擴展的時候是可以不大俠幫幫忙做的(MongoDB擴內(nèi)存和CPU的時候要欠費停機)。

和部分系統(tǒng)的交互使用到了RabbitMQ,而Spring Boot如果化入spring-boot-starter-amqp,不過就可以很方便些地能完成和RabbitMQ的板載顯卡;生產(chǎn)者和消費者都相當方便。

因為是純接口的服務(wù),就是為了減輕數(shù)據(jù)庫的壓力,所以才我們依據(jù)業(yè)務(wù)場景,將一些接口的結(jié)果就緩存到Redis中(數(shù)據(jù)變化不過度,但是業(yè)務(wù)場景的實時性要求也不是很高)。在集成顯卡Redis的時候,我們前后試了兩種

Spring Boot項目,再建議使用@Cacheable注解就可以結(jié)束和Redis最簡單的集成顯卡,但是當時只不過可以設(shè)置緩存的網(wǎng)絡(luò)錯誤時間夠不夠靈活自如,我們再后來把它改成了第二種方案;

在用RedisTemplate,可以不能夠完成對Redis的絕大部分你操作。

我將短短能分享Java開發(fā)、架構(gòu)設(shè)計、程序員職業(yè)發(fā)展等方面的見解,如果能能換取你的關(guān)注。

標簽: