0%

SpringCloud Service-producer

pom.xml

1
2
3
4
5
6
7
8
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

application.yml

1
2
3
4
5
6
7
8
9
10
11
12
13
server:
port: 7003

eureka:
instance:
hostname: localhost
client:
serviceUrl:
defaultZone: http://localhost:7001/eureka/ #注册中心的地址

spring:
application:
name: service-producer #服务的名字

启动类添加注解**@EnableDiscoveryClient**

RestController.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package com.linjian.serviceproducer.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
* ProducerController
*
* @author jlin
* @date 2019/3/19 22:20
* @Description
*/
@RestController
public class ProducerController {

@RequestMapping("/hello")
public String hello(@RequestParam String name) {
return "hello " + name + ",this is new world";
}
}