有了配置中心,所以微服务项目中application.properties文件的内容都可以提取到配置中心(除了连接配置中心属性)
1.配置中心中加入属性文件,zuul-gateway-[test|dev].properties
# web zuul.routes.api-web.path=/web/** zuul.routes.api-web.serviceId=front-service # mobile #zuul.routes.api-mobile.path=/mobile/** #zuul.routes.api-mobile.serviceId=mobile-service
2.zuul依赖如下
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-zuul</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-actuator</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency>
3.zuul中添加文件bootstrap.properties,删除application.properties
#对应配置中心的属性文件前缀 spring.application.name=zuul-gateway server.port=5555 eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/ spring.cloud.config.discovery.enabled=true spring.cloud.config.discovery.serviceId=config-server spring.cloud.config.profile=dev
1
1
1
1
1
1
1