Nyob rau lub caij nplooj ntoos hlav, "Autowiring los ntawm Hom" txhais tau tias, yog tias cov ntaub ntawv hom taum tau sib xws nrog cov ntaub ntawv ntawm lwm yam khoom taum, nws pib xaim nws. Piv txwv li, "tus neeg" taum nthuav tawm cov khoom ntiag tug nrog cov ntaub ntawv ntawm chav kawm "muaj peev xwm", Caij nplooj ntoos hlav yuav pom taum nrog tib cov ntaub ntawv ntawm chav kawm "muaj peev xwm" thiab xaim nws tau.
Koj puas tuaj yeem Autowire los ntawm hom?
hom no qhia autowiring los ntawm hom khoom. Lub thawv caij nplooj ntoos hlav saib cov taum uas autowire tus cwj pwm raug teeb tsa los ntawm Hom hauv cov ntaub ntawv XML teeb tsa. Nws mam li sim ua kom phim thiab xaim cov cuab yeej yog tias nws hom phim nrog ib qho ntawm cov taum lub npe hauv cov ntaub ntawv teeb tsa.
Muaj pes tsawg hom Autowiring muaj nyob rau lub caij nplooj ntoos hlav?
Yog li, Lub Caij Nplooj Ntoos Hlav tuaj yeem siv BeanFactory kom paub txog kev vam khom thoob plaws txhua qhov taum siv. XML-configuration-based autowiring functionality muaj tsib hom - tsis yog, byName, byType, constructor, thiab autodetect. Lub hom phiaj yog tsis muaj.
Vim li cas peb thiaj siv @autowired annotation?
Tus @Autowired annotation muab kev tswj hwm zoo dua nyob qhov twg thiab yuav ua li cas autowiring yuav tsum ua tiav. Cov lus qhia @Autowired tuaj yeem siv los ua autowire taum ntawm txoj kev teeb tsa ib yam li @Required annotation, constructor, ib qho cuab yeej lossis cov txheej txheem nrog cov npe tsis txaus ntseeg thiab / lossis ntau qhov kev sib cav.
Yuav ua li cas @inject in Spring?
@Inject yog ib feem ntawm Java thev naus laus zis hu ua CDI uas txhais tus qauv raukev txhaj tshuaj zoo ib yam li Spring. Hauv daim ntawv thov Caij nplooj ntoos hlav, ob lub ntsiab lus ua haujlwm ib yam li Caij Nplooj Hlav tau txiav txim siab los txhawb qee qhov JSR-299 annotations ntxiv rau lawv tus kheej.