Muaj pes tsawg hom Autowiring nyob rau lub caij nplooj ntoos hlav?
Muaj pes tsawg hom Autowiring nyob rau lub caij nplooj ntoos hlav?

Video: Muaj pes tsawg hom Autowiring nyob rau lub caij nplooj ntoos hlav?

Video: Muaj pes tsawg hom Autowiring nyob rau lub caij nplooj ntoos hlav?
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Tej zaum
Anonim

Caij nplooj ntoos hlav txhawb tsib hom autowiring thiab lawv tsis yog (default), byType, byName, constructor thiab autodetect.

Ib yam li ntawd, tib neeg nug, dab tsi yog hom Autowiring nyob rau lub caij nplooj ntoos hlav?

Qhov no txhais tau hais tias nws muaj peev xwm cia li cia Caij nplooj ntoos hlav daws cov neeg koom tes ( lwm yam taum) rau koj taum los ntawm kev tshuaj xyuas tus cov ntsiab lus ntawm tus BeanFactory. Qhov no hu ua caij nplooj ntoos hlav taum autowiring . Qhov autowiring functionality muaj plaub hom. Cov no yog 'tsis muaj', 'byName', 'byType' thiab 'constructor'.

Ib yam li ntawd, Autowiring nyob rau lub caij nplooj ntoos hlav yog dab tsi? Caij nplooj ntoos hlav nrhiav ib tug taum nrog tib lub npe raws li cov cuab yeej uas yuav tsum tau autowired . Rau piv txwv , yog taum txhais tau tias yog teem rau autowire los ntawm lub npe, thiab nws muaj ib tug tswv cuab (uas yog, nws muaj ib tug setMaster (..) txoj kev), Caij nplooj ntoos hlav nrhiav taum txhais lub npe hu ua tus tswv, thiab siv nws los teeb tsa cov cuab yeej.

Ib yam li ntawd, hom Autowire txawv li cas?

XML-configuration-based autowiring functionality muaj tsib hom - tsis yog, byName, byType , constructor, thiab autodetect. Lub default hom yog tsis muaj.

Vim li cas @autowired siv rau lub caij nplooj ntoos hlav?

Caij nplooj ntoos hlav ua tau autowire kev sib raug zoo ntawm kev sib koom tes taum yam tsis siv constructor-arg thiab cov khoom cim npe uas pab nrog tus nqi ntawm XML configuration. Autowiring ntawm Caij nplooj ntoos hlav lub moj khaum enables koj mus txhaj cov khoom dependency implicitly.

Pom zoo: