卖逼视频免费看片|狼人就干网中文字慕|成人av影院导航|人妻少妇精品无码专区二区妖婧|亚洲丝袜视频玖玖|一区二区免费中文|日本高清无码一区|国产91无码小说|国产黄片子视频91sese日韩|免费高清无码成人网站入口

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

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

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

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

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

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

eg:A依賴性太強(qiáng)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ā)框架?

就拿我們項(xiàng)目來舉例說明說一說吧。

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

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

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

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

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

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

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

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

標(biāo)簽: