spring的相關注解總結

@SuppressWarnings(“unchecked”)

告訴編譯器忽略 unchecked 警告信息,使用Redis時看到,詳細介紹

springboot相關注解

@SpringBootApplication

詳細介紹
springboot是通過註解@EnableAutoConfiguration的方式,去查找,過濾,加載所需的configuration,@ComponentScan掃描我們自定義的bean,@SpringBootConfiguration使得被@SpringBootApplication註解的類聲明爲註解類.因此@SpringBootApplication的作用等價於同時組合使用@EnableAutoConfiguration,@ComponentScan,@SpringBootConfiguration.

  • @ComponentScan
    會自動掃描指定包下的全部標有@Component的類,並註冊生成IOC容器中的bean,當然包括@Component下的子註解@Service,@Repository,@Controller,掃描範圍是@ComponentScan註解所在配置類包及子包的類
  • @EnableAutoConfiguration
    這個是springboot實現自動化配置的核心註解,通過這個註解把spring應用所需的bean注入容器中.@EnableAutoConfiguration源碼通過@Import注入了一個ImportSelector的實現類
  • @SpringBootConfiguration
    這個註解的作用與@Configuration作用相同,都是用來聲明當前類是一個配置類.可以通過@Bean註解生成IOC容器管理的bean.在QuickStartApplication中定義bean,並在@HelloController中注入使用

cloud 用到的註解

@EnableEurekaServer

在項目啓動類上使用@EnableEurekaServer,可以將項目作爲SpringCloud中的註冊中心。
詳細介紹

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章