2.eureka-client笔记

时间:2018-04-20 17:52:52 阅读:254次
eureka-client笔记

pom.xml

<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>
  <groupId>com.henan28.server</groupId>
  <artifactId>member</artifactId>
  <version>0.0.1-SNAPSHOT</version>

	<parent>
	    <groupId>org.springframework.boot</groupId>
	    <artifactId>spring-boot-starter-parent</artifactId>
	    <version>2.0.0.RELEASE</version>
	</parent>
	
	  
	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
		<java.version>1.8</java.version>
	</properties>
	
	<dependencyManagement>
	    <dependencies>
	        <dependency>
	            <groupId>org.springframework.cloud</groupId>
	            <artifactId>spring-cloud-dependencies</artifactId>
	            <version>Finchley.M9</version>
	            <type>pom</type>
	            <scope>import</scope>
	        </dependency>
	    </dependencies>
	</dependencyManagement>

	<dependencies>
	    <dependency>
	        <groupId>org.springframework.cloud</groupId>
	        <artifactId>spring-cloud-starter-eureka</artifactId>
	        <version>2.0.0.M2</version>
	    </dependency>
	    <dependency>
	        <groupId>org.springframework.boot</groupId>
	        <artifactId>spring-boot-starter-web</artifactId>
		 </dependency>	 
	</dependencies>
	<repositories>
    	<repository>
	        <id>spring-milestones</id>
	        <name>Spring Milestones</name>
	        <url>https://repo.spring.io/milestone</url>
	        <snapshots>
	            <enabled>false</enabled>
	        </snapshots>
	    </repository>
	</repositories>
</project>


application.properties

spring.application.name=service-member
server.port=8762  
eureka.client.serviceUrl.defaultZone=http://localhost:8888/eureka/


controller

@RestController
public class MemberController {
	@Value("${server.port}")
	private String serverPort;
	
	@RequestMapping("/getMember")	
	public List<String> getMember() {
		List<String> listUser =  new ArrayList<String>();
		listUser.add("Davek");
		listUser.add("wp");
		listUser.add("port:"+this.serverPort);
		return listUser;
	}
	
	@RequestMapping("/getMemberServiceApi")
	public String getMemberServiceApi() {
		return "这是member项目接口";
	}
}


app

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;

@SpringBootApplication
@EnableEurekaClient
public class MemberApp {
	public static void main(String[] args) {
		SpringApplication.run(MemberApp.class, args);
	}
}


扫描二维码关注程序员爱笔记,接收更多资讯

评论

快速评论