SpringBoot 常用注解
1、@SpringBootApplication
位置:SpringBoot启动类 / 引导类上
作用:标识该类为SpringBoot的启动类
2、@RestController
位置:Controller类上
作用:标识该类为Controller类,并且返回结果不跳转页面,相当于@Controller + @ResponseBody
备注:若使用该注解,该类只能返回数据,不能跳转页面,若想跳转页面,还需要使用@Controller + @ResponseBody
3、@ComponentScan(“扫描包”)
位置:SpringBoot启动类 / 引导类上
作用:用于扫描本项目中组件注解
4、@MapperScan(“扫描包”)
位置:SpringBoot启动类 / 引导类上
作用:用于扫描本项目中Mapper映射
5、@Mapper
位置:Mapper接口上
作用:标识该接口为Mapper接口,交给Spring管理
备注:@Mapper 注解需要在每个Mapper接口上添加,@MapperScan 注解只需要添加到启动类上,扫描指定包内的全部接口
6、@EnableTrancationManagement
位置:SpringBoot启动类 / 引导类上
作用:开启声明式事务管理
7、@Transactional
位置:需要事务管理的业务层方法上
作用:标识该方法需要进行事务管理
8、@Configuration
位置:需要设置为配置类的类上
作用:标识该类为配置类
9、@EnableRedisHttpSession
位置:Redis Session共享配置类上(使用@Configuration注解自定义配置类)
作用:标识开启Session共享
10、@ServletComponentSacn
位置:SpringBoot启动类 / 引导类上
作用:用于扫描@WebServlet、@WebListener、@WebFilter
待 续 …
SpringCloud 常用注解
1、@EnableEurekaServer
位置:SpringBoot启动类 / 引导类上
作用:启动Eureka服务器
2、@EnableDiscoveryClient
位置:SpringBoot启动类 / 引导类上
作用:启动Eureka服务发现客户端
3、@EnableFeignClients
位置:SpringBoot启动类 / 引导类上
作用:启动Netflix开发的声明式、模板化的HTTP客户端, Feign可以帮助我们更快捷、优雅地调用HTTP API
4、@FeignClient(“服务名”)
位置:Feign接口上
作用:标识该接口调用远程的服务
5、@EnableHystrix
位置:SpringBoot启动类 / 引导类上
作用:启动Hystrix熔断器
6、@HystrixCommand(fallbackMethod = “熔断服务后调用的方法名”)
位置:在调用服务器的Controller组件上
作用:当服务异常,熔断原有服务,将服务切换到对应方法上
待 续 …