Dab tsi yog qhov tsim nyog rau lub caij nplooj ntoo hlav?
Dab tsi yog qhov tsim nyog rau lub caij nplooj ntoo hlav?

Video: Dab tsi yog qhov tsim nyog rau lub caij nplooj ntoo hlav?

Video: Dab tsi yog qhov tsim nyog rau lub caij nplooj ntoo hlav?
Video: Tshuaj theem vim li cas thiaj tau nqi ?/ Siv kho mob dab tsi?/paris polyphylla use for? 2024, Tej zaum
Anonim

Cov @ Tsim nyog annotation yog siv los daws qhov teeb meem autowiring, thaum muaj ntau taum ntawm tib hom. Cov @ Tsim nyog annotation tuaj yeem siv rau ntawm txhua chav kawm sau nrog @Component lossis ntawm txoj kev piav qhia nrog @Bean. Cov lus piav qhia no tseem tuaj yeem siv rau ntawm tus tsim cov lus sib cav lossis cov txheej txheem tsis.

Tib neeg kuj nug, dab tsi yog lub caij nplooj ntoos hlav khau raj tsim nyog?

@Cov ntsiab lus yog qhov yooj yim Caij nplooj ntoos hlav annotation uas tso cai rau Tub kawm ntawv yuav raug kuaj los ntawm Caij nplooj ntoos hlav thawv. Cov @ Tsim nyog ("cov tub ntxhais kawm") tshwj xeeb txheeb xyuas cov taum no nrog "cov tub ntxhais kawm" txoj hlua. com/zetcode/model/Manager.java.

Kuj Paub, dab tsi yog lub caij nplooj ntoos hlav tivthaiv? Caij nplooj ntoos hlav Component annotation yog siv los qhia ib chav kawm li Cheebtsam . Nws txhais tau tias Caij nplooj ntoos hlav lub moj khaum yuav autodetect cov chav kawm no rau kev vam meej txhaj tshuaj thaum annotation-raws li configuration thiab classpath scanning yog siv.

Hauv qhov no, qhov txawv ntawm @autowired thiab @qualifier yog dab tsi?

Cov txawv yog li @ Autowired thiab @Qualifier yog lub caij nplooj ntoos hlav annotation thaum @Resource yog tus qauv java annotation (los ntawm JSR-250). Dhau li ntawd, @Resource tsuas yog txhawb rau thaj teb thiab teeb tsa kev txhaj tshuaj thaum @ Autowired txhawb teb, setter, constructors thiab multi-argument txoj kev txhaj tshuaj.

Dab tsi yog qualifier hauv Java?

Koj siv tau kev tsim nyog los muab ntau yam kev siv ntawm ib hom taum tshwj xeeb. A kev tsim nyog yog ib qho annotation uas koj siv rau taum. A kev tsim nyog hom yog a Java annotation txhais raws li @Target({METHOD, FIELD, PARAMETER, HOM}) thiab @Retention(RUNTIME).

Pom zoo: