一、常用注解
1、@RestController = @ResponseBody + @Controller
表示修飾該Controller所有的方法返回JSON格式數(shù)據(jù)而不是視圖,直接可以編寫
Restful接口
2、@ComponentScan等價于 <context:component-scan basepackage=""/>表示程序啟動是,自動掃描當(dāng)前包及子包下所有類
3、@Configuration等價于applicationContext.xml 表示將該類作用springboot配置文件類
4、@Import 等價于applicationContext.xml中的<import>標(biāo)簽
5、@Bean 等價于applicationContext.xml中的<bean id/name>標(biāo)簽
6、@Scope 等價于applicationContext.xml中的<bean>標(biāo)簽中的scope屬性
二、啟動類相關(guān)配置
@SpringBootAppliaction=@Configuration+@ComponentScan+@EnableAutoConfiguration
@SpringBootAppliaction在類上加入,實(shí)際上就是注解的整合,能夠作為啟動類,包掃描(只限于當(dāng)前同級包下)
三、加載類相關(guān)配置
1、@EnableAutoConfiguration 表示程序啟動時,自動加載springboot默認(rèn)的配置
2、@EnableConfigurationProperties(ThymeleafProperties.class) 加載properties 對應(yīng)的類
3、@ConditionalOnClass(SpringTemplateEngine.class) 這是代表了條件的注解,該主鍵中傳遞的參數(shù)是用來判斷的
4、@AutoConfigureAfter(WebMvcAutoConfiguration.class) 在參數(shù)中聲明的類加載完了之后,才會去自動配置
四、測試相關(guān)配置
@RunWith(SpringRunner.class) SpringRunner 繼承了SpringJunit4Runner
@SpringBootTest 這里可以換成@ContextConfiguration