Video: Qhov txawv ntawm @autowired thiab @bean yog dab tsi?
2024 Tus sau: Lynn Donovan | [email protected]. Kawg hloov kho: 2023-12-15 23:47
Thaum koj siv @ Taum koj yog lub luag haujlwm muab tus ID thiab hu rau tus ID thaum koj xav siv cov khoom tshwj xeeb uas siv getBean() txoj kev. Autowired pab kom tsis txhob hu xov tooj thiab xa rov qab ib yam khoom txhua zaus nws xav tau.
Tsis tas li ntawd, siv @autowired yog dab tsi?
Cov @ Autowired annotation muab ntau zoo-grained tswj nyob qhov twg thiab yuav ua li cas autowiring yuav tsum ua kom tiav. Cov @ Autowired annotation tuaj yeem siv tau autowire taum ntawm tus txheej txheem setter ib yam li @Required annotation, constructor, ib lub cuab yeej los yog txoj kev nrog arbitrary npe thiab / los yog ntau yam kev sib cav.
Ib sab saum toj no, @bean annotation ua dab tsi? Caij nplooj ntoos hlav @ Bean Annotation . Caij nplooj ntoos hlav @ Bean Annotation yog siv rau ntawm ib txoj kev qhia tias nws rov qab a taum kom tswj tau los ntawm Spring context. Caij nplooj ntoos hlav Taum annotation feem ntau yog tshaj tawm hauv Configuration classes method. Hauv qhov no, taum txoj kev yuav siv lwm yam @ Taum txoj hauv kev hauv tib chav kawm los ntawm kev hu ncaj qha.
Tsis tas li ntawd, dab tsi yog lub noob taum hauv caij nplooj ntoos hlav khau?
Cov khoom uas tsim cov caj qaum ntawm koj daim ntawv thov thiab uas yog tswj los ntawm cov Caij nplooj ntoos hlav IoC thawv hu ua taum . A taum yog ib yam khoom uas yog instantiated, assembled, thiab lwm yam tswj los ntawm a Caij nplooj ntoos hlav IoC thawv. Cov no taum yog tsim nrog cov txheej txheem metadata uas koj muab rau lub thawv.
Kev txhaj tshuaj taum yog dab tsi?
Txhaj Taum . Txhawm rau siv lub taum koj tsim, koj txhaj lawv mus rau lwm qhov taum uas tuaj yeem siv los ntawm daim ntawv thov, xws li JavaServer Faces daim ntawv thov. Piv txwv li, koj tuaj yeem tsim ib qho taum hu rau lub tshuab luam ntawv uas koj xav tau txhaj ib tug ntawm Nyob Zoo taum : import javax. txhaj.