Cov txheej txheem:
Video: Kev siv Autowired 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
Caij nplooj ntoos hlav @ Autowired annotation yog siv rau kev txhaj tshuaj tsis siv neeg dependency. Caij nplooj ntoos hlav lub moj khaum yog tsim los ntawm kev vam khom txhaj tshuaj thiab peb txhaj cov chav kawm dependencies los ntawm caij nplooj ntoos hlav taum configuration file.
Khaws qhov no hauv kev txiav txim siab, dab tsi yog kev siv @autowired nyob rau lub caij nplooj ntoo hlav?
Autowiring feature ntawm caij nplooj ntoos hlav lub moj khaum enables koj mus txhaj cov khoom dependency implicitly. Nws sab hauv siv setter los yog constructor txhaj. Autowiring ua tsis tau siv txhaj tshuaj primitive thiab hlua qhov tseem ceeb. Nws ua haujlwm nrog kev siv nkaus xwb.
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.
Tsis tas li ntawd, kev siv Autowired annotation yog dab tsi?
Cov @ Autowired annotation muab kev tswj kom zoo dua nyob qhov twg thiab yuav ua li cas autowiring yuav tsum ua kom tiav. Cov @ Autowired annotation tuaj yeem yog siv rau autowire taum ntawm tus txheej txheem setter ib yam li @Required lus piav qhia , constructor, ib qho cuab yeej lossis txoj hauv kev nrog cov npe arbitrary thiab / lossis ntau qhov kev sib cav.
Dab tsi yog cov lus piav qhia siv rau lub caij nplooj ntoos hlav?
Qee qhov tseem ceeb Spring MVC annotations yog:
- @Controller.
- @RequestMapping.
- @PathVariable.
- @RequestParam.
- @ModelAttribute.
- @RequestBody thiab @ResponseBody.
- @RequestHeader thiab @ResponseHeader.
Pom zoo:
@ResponseBody annotation nyob rau lub caij nplooj ntoos hlav yog dab tsi?
Cov lus siv: Java, JSON
Cron kev qhia yog dab tsi nyob rau lub caij nplooj ntoos hlav?
Ib qho Cron qhia muaj rau qhov ua ntu zus - thib ob, feeb, teev, hnub ntawm lub hli, hli, hnub (s) ntawm lub lim tiam.thiab tau tshaj tawm raws li hauv qab no @Scheduled(cron = '* * * * **')
Kev siv @value annotation nyob rau lub caij nplooj ntoos hlav yog dab tsi?
Spring @PropertySource annotations yog tsuas yog siv los nyeem los ntawm cov ntaub ntawv khoom 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
Dab tsi yog kev siv cov tshuaj tivthaiv scan nyob rau lub caij nplooj ntoos hlav?
Siv cov khoom siv tshuaj ntsuam xyuas yog ib txoj hauv kev nug Spring kom paub txog Spring-managed Cheebtsam. Caij nplooj ntoos hlav xav tau cov ntaub ntawv los nrhiav thiab sau npe tag nrho cov Caij Nplooj Ntoos Hlav nrog cov ntsiab lus ntawm daim ntawv thov thaum daim ntawv thov pib
Dab tsi yog kev siv ntawm @repository annotation nyob rau lub caij nplooj ntoo hlav?
Spring @Repository Annotation. Caij nplooj ntoos hlav @Repository annotation yog siv los qhia tias cov chav kawm muab cov txheej txheem rau kev khaws cia, rov qab, tshawb nrhiav, hloov kho thiab rho tawm haujlwm ntawm cov khoom