一、创建SpringBoot项目springcloud-eureka-client-order,过程如上一篇,有一点需要注意,选择Eureka客户端依赖
二、配置文件
1、pom.xml
4.0.0
org.springframework.boot
spring-boot-starter-parent
2.1.4.RELEASE
com.jane
springcloud-eureka-client-order
0.0.1-SNAPSHOT
springcloud-eureka-client-order
Demo project for Spring Boot
1.8
Greenwich.SR1
org.springframework.cloud
spring-cloud-starter-netflix-eureka-client
org.springframework.boot
spring-boot-starter-test
test
org.springframework.boot
spring-boot-starter-web
org.springframework.cloud
spring-cloud-starter-openfeign
2.0.2.RELEASE
org.springframework.cloud
spring-cloud-openfeign-core
2.0.2.RELEASE
io.github.openfeign.form
feign-form-spring
3.2.2
org.springframework.cloud
spring-cloud-dependencies
${spring-cloud.version}
pom
import
org.springframework.boot
spring-boot-maven-plugin
2、启动文件
package com.jane.springcloudeurekaclientorder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.context.annotation.ComponentScan;
@EnableDiscoveryClient
@SpringBootApplication
@ComponentScan("com.jane")
@EnableFeignClients
public class SpringcloudEurekaClientOrderApplication {
public static void main(String[] args) {
SpringApplication.run(SpringcloudEurekaClientOrderApplication.class, args);
}
}
3、application.properties
server.port=6010
spring.application.name=springcloud-eureka-client-order
eureka.client.serviceUrl.defaultZone=http://127.0.0.1:6001/eureka/
4、服务提供API,TestController
package com.jane.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class TestController {
@Value("${server.port}")
String port;
@RequestMapping(value = "/test", method = RequestMethod.GET)
public String test(){
return "hello,this is client-order:" + port;
}
}
三、启动服务
1、服务正常
2、查看注册中心
创新互联www.cdcxhl.cn,专业提供香港、美国云服务器,动态BGP最优骨干路由自动选择,持续稳定高效的网络助力业务部署。公司持有工信部办法的idc、isp许可证, 机房独有T级流量清洗系统配攻击溯源,准确进行流量调度,确保服务器高可用性。佳节活动现已开启,新人活动云服务器买多久送多久。