Video: Kev siv @value annotation nyob rau lub caij nplooj ntoos hlav yog dab tsi?
2024 Tus sau: Lynn Donovan | [email protected]. Kawg hloov kho: 2023-12-15 23:47
Spring @PropertySource annotations yog siv los nyeem los ntawm khoom cov ntaub ntawv siv Spring's Environment interface. Cov lus piav qhia no yog nyob rau hauv kev xyaum, muab tso rau ntawm @Configuration chav kawm. Caij nplooj ntoos hlav @Value annotation tuaj yeem siv los qhia cov lus qhia ntawm daim teb lossis txoj hauv kev. Cov ntaub ntawv siv feem ntau yog qhia cov cuab yeej los ntawm a.
Raws li, kev siv ntawm @value annotation yog dab tsi?
Caij nplooj ntoos hlav @ Nqe lus piav qhia yog siv los txhaj tus nqi nyob rau hauv variables thiab method arguments. Peb tuaj yeem nyeem qhov hloov pauv ib puag ncig caij nplooj ntoos hlav lossis lub cev hloov pauv. Nws kuj txhawb SpEL.
Tsis tas li ntawd, koj yuav txhaj tshuaj Spring values li cas? Yuav ua li cas txhaj tus nqi rau hauv Bean cov khoom hauv Caij nplooj ntoos hlav
- Tsim ib qhov project Maven tshiab. Mus rau Cov Ntaub Ntawv -> Project -> Maven -> Maven Project.
- Ntxiv Caij nplooj ntoos hlav 3.2. 3 kev vam meej.
- Tsim ib qho yooj yim Spring Bean nrog cov khoom.
- XML-raws li txoj hauv kev rau kev txhaj tshuaj rau hauv cov khoom taum.
- Khiav daim ntawv thov.
- Tso zis.
Tom qab ntawd, ib tug kuj nug, dab tsi yog kev siv @value nyob rau lub caij nplooj ntoos hlav?
Caij nplooj ntoos hlav @ Tus nqi annotation yog siv los muab default tus nqi rau variables thiab method arguments. Peb nyeem tau caij nplooj ntoos hlav ib puag ncig variables raws li zoo raws li qhov system variables siv @ Tus nqi lus piav qhia. Caij nplooj ntoos hlav @ Tus nqi annotation kuj txhawb SpEL.
Yuav ua li cas koj Autowire annotation nyob rau lub caij nplooj ntoos hlav?
Feem ntau, koj yuav xav tau autowired cov cuab yeej nyob rau hauv ib qho taum tshwj xeeb nkaus xwb. Hauv Caij nplooj ntoos hlav , koj ua tau siv @ Autowired annotation rau nws pib hlau taum ntawm tus txheej txheem setter, constructor los yog teb. Ntxiv mus, nws tuaj yeem autowired vaj tse nyob rau hauv ib lub noob taum. Cov @ Autowired annotation yog nws pib xaim cov taum los ntawm kev sib piv cov ntaub ntawv hom.