springCloud当中Eureca服务提供者Provider的部署

服务提供者的部署
马克-to-win@马克java社区:做个普通的maven project,quickstart archetype。改成jdk.8。运行程序后会出现:EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.这个提示跟保护模式相关,和我们的Helloworld例子无关,这里就略过了。马克-to-win@马克java社区:当然,可以在前面的server配置文件处,把它关了,enable-self-preservation:false。马克-to-win@马克java社区:另外,Eureka本身是一个基于REST的服务,所以你会发现大家通常的服务或消费微服务,都做成是基于REST的服务。马克- to-win:马克 java社区:防盗版实名手机尾号: 73203。




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</groupId>
    <artifactId>EurecaMaven2</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>
    <name>EurecaMaven2</name>
    <url>http://maven.apache.org</url>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
        <relativePath />
    </parent>
   
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Camden.SR2</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka</artifactId>
        </dependency>
    </dependencies>
</project>






application.yml:


server:
  port: 9090    
spring:
  application:
    name: provider 
eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

     





package com.EurecaMaven2;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/*EnableEurekaClient的意思是让你的应用成为eureca的客户,你在用它,你是他的客户,你没在用别人,没有它,不报错,但是8761服务器发现不了这个client。整个euraka的helloworld三个项目,包括服务器,provider,consumer不能正确配合工作。*/
@SpringBootApplication
@EnableEurekaClient
@RestController
public class Application {
         @RequestMapping("/")
        public String home() {
            return "Hello world 马克-to-win";
        }
        
         @RequestMapping("/acquire")
        public String acquire() {
            return "Hello 马克-to-win acquire";
        }

        public static void main(String[] args) {
            SpringApplication.run(Application.class,args);
        }
}




运行结果:






























以上是我们独立用浏览器测试服务提供者。没什么问题,以下我们可以在程序中测试以上服务提供者。