微服务注解详解

@Controller:修饰class,用来创建处理http请求的对象

@RestController:Spring4之后加入的注解,原来在@Controller中返回json需要

@ResponseBody来配合,如果直接用@RestController替代@Controller就不需要再配
置@ResponseBody,默认返回json格式。

@RequestMapping:配置url映射



@SpringBootApplication:主类声明

@EnableEurekaServer 注解启动一个服务注册中心提供给其他应用进行对话

@EnableDiscoveryClient 注解,该注解能激活Eureka中的 服务类的 实现,才能实现Controller中对服务信息的输出。

@EnableCircuitBreaker 注解开启断路器功能:

@EnableZuulProxy 注解开启Zuul

@SpringCloudApplication 注解,它整合了 @SpringBootApplication @EnableDiscoveryClient @EnableCircuitBreaker ,主要目的还是简化配置

使用@EnableEurekaClient就能简单的开启Eureka Client中的功能

通过 @EnableWebSecurity 注解开启Spring Security的功能

@ComponentScan(basePackages={"com.fiberhome.config"}) 组件扫描,可自动发现和装配一些Bean

@Configuration 等同于spring的XML配置文件;使用java代码可以检查类型安全

@EnableAutoConfiguration 自动配置

@Component可配合CommandLineRunner使用,在程序启动后执行一些基础任务

eg:
@Component
public class MyCommandLineRunner implements CommandLineRunner{

@Autowired
private UserService userService;
@Override
public void run(String... arg0) throws Exception {
User user = userService.findByUserAcount("admin");
System.out.println(user.getAcount());
}

}

你可能感兴趣的:(微服务)