Video: @ComponentScan yog dab tsi?
2024 Tus sau: Lynn Donovan | [email protected]. Kawg hloov kho: 2023-12-15 23:47
Cov @ ComponentScan annotation yog siv nrog @Configuration annotation qhia rau lub caij nplooj ntoos hlav cov pob khoom los luam theej duab rau cov lus piav qhia. Thaum koj qhia meej basePackageClasses, Caij nplooj ntoos hlav yuav luam theej lub pob (thiab subpackages) ntawm cov chav kawm uas koj teev.
Cov lus nug tseem yog, qhov txawv ntawm @component thiab @ComponentScan yog dab tsi?
Siv cov lus piav qhia @ ComponentScan , koj tuaj yeem qhia Spring qhov twg ua koj lub Caij Nplooj Hlav-tswj cov khoom dag. Ntawm qhov tod tes, @ Cheebtsam yog ib qho kev piav qhia dav dav rau ib qho Spring-Managed tiv thaiv . Rau piv txwv - Yog tias koj tsim ib chav kawm hu ua Testing hauv pob com.
Dab tsi annotation yog siv rau nws pib scans? Spring @Component, @Service, @Repository thiab @Controller cov lus piav qhia yog siv rau tsis siv neeg nrhiav tau taum siv classpath scan hauv Caij nplooj ntoos hlav moj khaum. @Component yog generic lus piav qhia.
Tsis tas li, kev siv @SpringBootApplication yog dab tsi?
Spring Boot @ SpringBootApplication annotation yog siv txhawm rau kos cov chav kawm teeb tsa uas tshaj tawm ib lossis ntau dua @Bean txoj kev thiab tseem ua rau nws pib teeb tsa thiab kev tshuaj ntsuam xyuas. Nws zoo ib yam li tshaj tawm cov chav kawm nrog @Configuration, @EnableAutoConfiguration thiab @ComponentScan annotations.
Qhov txawv ntawm @SpringBootApplication thiab @EnableAutoConfiguration yog dab tsi?
@ComponentScan qhia Spring saib rau lwm yam khoom, configuration, thiab cov kev pab cuam hauv pob ntawv qhia. Caij nplooj ntoos hlav tuaj yeem pib scan, kuaj xyuas thiab sau npe koj cov taum lossis cov khoom siv los ntawm pob ntawv npaj ua ntej. Yog tias tsis muaj pob ntawv teev cov chav kawm tam sim no raug coj los ua cov pob hauv paus.