閱讀目錄

一、Spring自動(dòng)組件掃描

Spring 提供組件掃描(component scanning)功能。它能從指定的classpath里自動(dòng)掃描、偵測(cè)和實(shí)例化具有特定注解的組件。

基本的注解是@Component,@Name它標(biāo)識(shí)一個(gè)受Spring管理的組件。其他特定的注解有@Repository、@Service和@Controller,它們分別標(biāo)識(shí)了持久層注解、業(yè)務(wù)層注解和控制層注解的組件。

1.@Component,@PostConstruct,PreDestroy注解掃描

1.1)在配置文件添加自動(dòng)組件掃描配置

網(wǎng)友評(píng)論