一、SpringCloud Config配置中心:
1. pom.xml配置如下:
<dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Camden.SR6</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement>
2. 启动类:
@SpringBootApplication @EnableEurekaClient @EnableConfigServer public class ConfigcenterApplication {
public static void main(String[] args) { // TODO Auto-generated method stub SpringApplication.run(ConfigcenterApplication.class, args); }
}
3. 启动配置(application.properties):
server.port=8096 spring.application.name=configCenter eureka.client.service-url.defaultZone=http://localhost:8764/eureka/ spring.cloud.config.server.git.uri=https://gitee.com/xiao-long-86/config-repository/ spring.cloud.config.server.git.username=515699390@qq.com spring.cloud.config.server.git.password=xl372068
二、SpringCloud produc具体应用:
1. pom.xml配置如下:
<dependencies>
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-client</artifactId> <version>1.3.0.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency>
</dependencies>
2. 启动类:
@SpringBootApplication @EnableEurekaClient public class ProductApplication {
public static void main(String[] args) { // TODO Auto-generated method stub SpringApplication.run(ProductApplication.class, args); }
}
3. 启动配置(application.properties改成bootstrap.properties,bootstrap.properties优先执行):
spring.application.name=productService eureka.client.service-url.defaultZone=http://localhost:8764/eureka/ spring.cloud.config.discovery.enabled=true spring.cloud.config.discovery.service-id=CONFIGCENTER spring.cloud.config.profile=dev
4. Gitee上的配置文件( productService-dev.properties):
server.port=8070
spring.application.name=productService
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=3000
hystrix.command.consumer.circuitBreaker.enabled=true
hystrix.command.consumer.circuitBreaker.requestVolumeThreshold=10
hystrix.command.consumer.circuitBreaker.sleepWindowInMilliseconds=10000
hystrix.command.consumer.circuitBreaker.errorThresholdPercentage=60
env=dev
SpringCloud微服务项目启动的过程:
先启动注册中心,再启动配置中心,最后启动具体应用。
|