基於Finchley.SR2的springcloud系列代碼(consumer 服務消費者)(五)

備註:源代碼已經全部上傳到github有錯誤地方請指正,謝謝!地址:https://github.com/hcmony/springcloud 

1,pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<parent>
		<groupId>com.hcmony</groupId>
		<artifactId>springcloud</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>

	<artifactId>consumer</artifactId>
	<packaging>jar</packaging>

	<dependencies>
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-zipkin</artifactId>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>


</project>

 

2,配置文件

server.port=8092
eureka.client.service-url.defaultZone= http://localhost:8888/eureka/
spring.application.name=consumer
eureka.instance.preferIpAddress=true
eureka.instance.instance-id=${spring.cloud.client.ip-address}:${server.port}

spring.zipkin.base-url=http://localhost:8200

#暴露actuator的所有端點
management.endpoints.web.exposure.include=*
##health endpoint是否必須顯示全部細節。默認情況下, /actuator/health 是公開的,並且不顯示細節
management.endpoint.health.show-details=always

3,java代碼

package com.hcmony;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

@EnableFeignClients
@EnableDiscoveryClient
@SpringBootApplication
public class ConsumerApplication {

	public static void main(String[] args) {
		SpringApplication.run(ConsumerApplication.class, args);
	}
}
package com.hcmony.controller;

import com.hcmony.service.ConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <h3>Shenjue.java基本描述</h3>
 * <p></p>
 *
 * @author com.hcmony
 * @since V1.0.0, 2019/03/04 16:52
 */
@RestController
public class ConsumerController {

	@Autowired
	private ConsumerService consumerService;

	@RequestMapping("test")
	public String test(String s){
		return consumerService.test(s);
	}
}
package com.hcmony.service;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * <h3>Shenjue.java基本描述</h3>
 * <p></p>
 *
 * @author com.hcmony
 * @since V1.0.0, 2019/03/04 16:52
 */
@FeignClient(value = "provider")
public interface ConsumerService {

	@RequestMapping("/test")
	public String test(@RequestParam("s") String s);

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章