@SpringCloudApplication是一个注解的集合,其中包含@SpringBootApplication
//@EnableCircuitBreaker
//@EnableDiscoveryClient
//@SpringBootApplication
/**
* @SpringCloudApplication相当于以下三个:
* @SpringBootApplication //SpringBoot注解
* @EnableDiscoveryClient //注册服务中心Eureka注解
* @EnableCircuitBreaker //断路器注解
*/
@EnableFeignClients
@SpringCloudApplication
public class Sp04OrderserviceApplication {
public static void main(String[] args) {
SpringApplication.run(Sp04OrderserviceApplication.class, args);
}
}
除了上面所说的@SpringBootApplication,注解@SpringCloudApplication总共包含了:@SpringBootApplication、@EnableDiscoveryClient、@EnableCircuitBreaker,分别是SpringBoot注解、注册服务中心Eureka注解、断路器注解。对于SpringCloud来说,这是每一微服务必须应有的三个注解,故可以用@SpringCloudApplication代替他们三个;
如果你要是用@SpringCloudApplication ,除了需要引入SpringBoot的依赖之外,你依旧的添加eureka、hystrix的依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
</dependency>
网友评论