springcloud服务提供者

启动时先启动注册中心,在启动服务提供者

1.pom

<?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">
    <parent>
        <artifactId>com.zx.dt2b.erp</artifactId>
        <groupId>com.zx.dt2b.erp</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>

    <artifactId>customer-service</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- 标识这个工程是一个服务,需要引入此jar -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <!-- 动态刷新的一个模块jar:用于处理其他的 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>
    <!--eureka版本-->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <!-- <version>Dalston.SR5</version>  -->
                <version>Edgware.SR4</version>
                <!-- <version>Finchley.SR1</version>  -->
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <finalName>customer-service-provider</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.zx.dt2b.CustomerApplication</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>


</project>

2.入口application

package com.zx.dt2b;

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

/**
 * Author:码图科技
 * Date:2018至今
 * Description:版权所有,违者必究
 */
@EnableDiscoveryClient    //标识具体的一个服务,需要向注册中心注册
@SpringBootApplication	//SpringBoot 核心配置
public class CustomerApplication {
    public static void main(String[] args) {
        SpringApplication.run(CustomerApplication.class, args);
    }
}

3.定义测试接口

package com.bfxy.springcloud.api;

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

@RestController
public class IndexController {

	@RequestMapping(value="/index", method = {RequestMethod.GET})
	public String hello() {
		return "Hello World!";
	}
	
	
}

4.配置:注册到注册中心

spring.application.name=customer-service
server.context-path=/
server.port=7001

##需要引入eureka注册中心的地址
eureka.instance.prefer-ip-address=true
#注册后能显示自己的ip地址
eureka.instance.instance-id=${spring.application.name}:${spring.cloud.client.ipAddress}:${server.port}
##租期更新时间间隔
eureka.instance.lease-renewal-interval-in-seconds=10
##租期的到期时间间隔
eureka.instance.lease-expiration-duration-in-seconds=30 
##开启健康检查(必须要引入spring-boot-starter-actuator)
eureka.client.healthcheck.enabled=true  
#注册到对应注册中心
eureka.client.service-url.defaultZone=http://eureka1:8001/eureka

对应下图:eureka.instance.instance-id=${spring.application.name}:${spring.cloud.client.ipAddress}:${server.port}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

择业

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值