当前位置: 首页 > news >正文

珠海网站建设制作设计产品宣传方案

珠海网站建设制作设计,产品宣传方案,手表网站排名186信息网,购物网站发展规划与建设进度1、Eureka 简介 Eureka 是Spring Cloud Netflix 微服务套件中的一部分, 它基于Netflix Eureka 做了二次封装, 主要负责完成微服务架构中的服务治理功能。我们只需通过简单引入依赖和注解配置就能让Spring Boot 构建的微服务应用轻松地与Eureka 服务治理…

1、Eureka 简介

Eureka 是Spring Cloud Netflix 微服务套件中的一部分, 它基于Netflix Eureka 做了二次封装, 主要负责完成微服务架构中的服务治理功能。我们只需通过简单引入依赖和注解配置就能让Spring Boot 构建的微服务应用轻松地与Eureka 服务治理体系进行整合。

Eureka包含两个组件:Eureka Server(注册中心)和Eureka Client (微服务)。

Eureka Server提供服务注册服务。

Eureka Client是一个java客户端,用来简化与Eureka Server的交互、客户端同时也就是一个内置的、使用轮询(round-robin)负载算法的负载均衡器。

 

 

2、搭建 SpringCloud 父工程

 按照下图配置即可

 这里不选择任何依赖。

 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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><packaging>pom</packaging><modules><module>EurekaServer01</module></modules><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.8.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.helloparent</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><name>demo</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Hoxton.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

 删除如下:这些文件夹没有用,直接删除即可,必须保留 pom.xml。

3、 创建 Maven 工程(注册中心 Eureka)

 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>demo</artifactId><groupId>com.helloparent</groupId><version>0.0.1-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>EurekaServer01</artifactId><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-server</artifactId></dependency></dependencies></project>

在新建的maven项目下面 src-->main-->resources建立一个application.yml文件

#内置的tomcat服务启动监听端口号
server:port: 8888
#应用名称
spring:application:name: EurekaServer01
#EurekaServer配置
eureka:instance:hostname: localhostserver:#关闭自我保护模式(缺省为打开)enable-self-preservation: false#扫描失效服务的间隔时间(缺省为60*1000ms)eviction-interval-timer-in-ms: 1000client:register-with-eureka: false #此EurekaServer不在注册到其他的注册中心fetch-registry: false       #不在从其他中心中心拉取服务器信息service-url:defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka #注册中心访问地址

在main下面创建文件夹及文件,注意main函数文件名。

package com.eureka.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;@SpringBootApplication
@EnableEurekaServer
public class EurekaServer01Start {public static void main(String[] args) {SpringApplication.run(EurekaServer01Start.class, args);}
}

运行查看结果。

主界面中

system status 为系统信息

General Info 为一般信息

Instances currently registered with Eureka 为注册到注册中心的所有微服务列表

4、创建第二个Maven 项目(接口)

创建文件夹及Service,如下图。

编写接口

package com.HelloInterface01.demo.service;public interface HelloService {public String sayHello();}

注释掉 父工程里面的相关代码

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><packaging>pom</packaging><modules><module>EurekaServer01</module><module>HelloInterface01</module></modules><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.3.8.RELEASE</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.helloparent</groupId><artifactId>demo</artifactId><version>0.0.1-SNAPSHOT</version><name>demo</name><description>Demo project for Spring Boot</description><properties><java.version>1.8</java.version></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>Hoxton.RELEASE</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><!--    <build>-->
<!--        <plugins>-->
<!--            <plugin>-->
<!--                <groupId>org.springframework.boot</groupId>-->
<!--                <artifactId>spring-boot-maven-plugin</artifactId>-->
<!--            </plugin>-->
<!--        </plugins>-->
<!--    </build>--></project>

5、服务提供者创建

<?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>demo</artifactId><groupId>com.helloparent</groupId><version>0.0.1-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>HelloProvide01</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>com.helloparent</groupId><artifactId>HelloInterface01</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies></project>

在resources文件夹下面添加一个yml。

spring:application:name: HelloProvider01
server:port: 9001
eureka:client:service-url:defaultZone: http://localhost:8888/eureka

创建如下文件夹及实现类

package com.HelloProvide.demo.service.Impl;import com.HelloInterface01.demo.service.HelloService;
import org.springframework.stereotype.Service;@Service
public class HelloServiceImpl implements HelloService {@Overridepublic String sayHello() {return "hello Eureka!";}
}

在创建一个controller 文件夹及文件

package com.HelloProvide.demo.controller;import com.HelloInterface01.demo.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HelloController {@Autowiredprivate HelloService helloService;@GetMapping("/hello")public String sayHello(){return helloService.sayHello();}
}

 编写启动类。

package com.HelloProvide.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;@SpringBootApplication
@EnableDiscoveryClient
public class HelloProvider01Start {public static void main(String[] args) {SpringApplication.run(HelloProvider01Start.class,args);}
}

 服务已经注册上去了。

6、服务调用者创建

 修改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>demo</artifactId><groupId>com.helloparent</groupId><version>0.0.1-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>HelloConsumer01</artifactId><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-netflix-eureka-client</artifactId></dependency><dependency><groupId>com.helloparent</groupId><artifactId>HelloInterface01</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies></project>

编写yml配置文件

spring:application:name: helloConsumer01
server:port: 9002eureka:client:service-url:defaultZone: http://localhost:8888/eureka

编写启动类

 

package com.HelloConsumer.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;@SpringBootApplication
@EnableDiscoveryClientpublic class HelloConsumer01Start {@Beanpublic RestTemplate restTemplate(){return new RestTemplate();}public static void main(String[] args) {SpringApplication.run(HelloConsumer01Start.class,args);}
}

实现类代码:注意导包别错误。

package com.HelloConsumer.demo.Service.impl;import com.HelloInterface01.demo.service.HelloService;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;import java.util.List;@Service
public class HelloServiceImpl implements HelloService {@Autowiredprivate DiscoveryClient discoveryClient; //是一个服务查询工具,可以连接到EurekaServer,根据服务名称去查询服务信息,注意别导错包了@Autowiredprivate RestTemplate restTemplate;  //调用rest风格接口工具类//从EurekaServer获取对应服务的地址和端口public String getServerInfo() {List<ServiceInstance> instanceList = discoveryClient.getInstances("HELLOPROVIDER01");if (instanceList != null && instanceList.size() > 0) {ServiceInstance serviceInstance = instanceList.get(0);//获取对应服务的主机地址String host = serviceInstance.getHost();//获取对应服务端口号int port = serviceInstance.getPort();return "http://" + host + ":" + port;}return null;}@Overridepublic String sayHello() {ResponseEntity<String> responseEntity = restTemplate.getForEntity(getServerInfo() + "/hello", String.class);String body = responseEntity.getBody();System.out.println("调用远程服务返回值:" + body);return body;}
}

编写controller

package com.HelloConsumer.demo.controller;import com.HelloInterface01.demo.service.HelloService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class HelloControllerConsumer {@Autowiredprivate HelloService helloService;@RequestMapping("/testHello")public String sayHello(){return helloService.sayHello();}
}

启动服务,注册中心成功。

7、进行测试

http://localhost:9002/testHello

 

 


文章转载自:
http://primp.rtkz.cn
http://munition.rtkz.cn
http://gluteal.rtkz.cn
http://vividly.rtkz.cn
http://outgrowth.rtkz.cn
http://fasciculus.rtkz.cn
http://microporosity.rtkz.cn
http://mosasaur.rtkz.cn
http://peevish.rtkz.cn
http://prosencephalon.rtkz.cn
http://sevenfold.rtkz.cn
http://chafing.rtkz.cn
http://cocktail.rtkz.cn
http://amalgamative.rtkz.cn
http://hayrake.rtkz.cn
http://consultation.rtkz.cn
http://withheld.rtkz.cn
http://xenogamy.rtkz.cn
http://doghouse.rtkz.cn
http://epidemical.rtkz.cn
http://herbaria.rtkz.cn
http://ultrapure.rtkz.cn
http://eyeservant.rtkz.cn
http://tapsalteerie.rtkz.cn
http://tumtum.rtkz.cn
http://asin.rtkz.cn
http://gallio.rtkz.cn
http://tussor.rtkz.cn
http://intimate.rtkz.cn
http://clone.rtkz.cn
http://kyoto.rtkz.cn
http://fancify.rtkz.cn
http://fifie.rtkz.cn
http://mmcd.rtkz.cn
http://criminology.rtkz.cn
http://serigraph.rtkz.cn
http://euglenoid.rtkz.cn
http://confiding.rtkz.cn
http://vampire.rtkz.cn
http://onwards.rtkz.cn
http://equitable.rtkz.cn
http://beestings.rtkz.cn
http://protractile.rtkz.cn
http://textualism.rtkz.cn
http://tying.rtkz.cn
http://evident.rtkz.cn
http://nonresidence.rtkz.cn
http://sootily.rtkz.cn
http://hunk.rtkz.cn
http://lusi.rtkz.cn
http://unconcerned.rtkz.cn
http://ornithological.rtkz.cn
http://belitoeng.rtkz.cn
http://nacred.rtkz.cn
http://rollicksome.rtkz.cn
http://suxamethonium.rtkz.cn
http://ambivert.rtkz.cn
http://traduce.rtkz.cn
http://tatary.rtkz.cn
http://churchgoer.rtkz.cn
http://cooperage.rtkz.cn
http://semimajor.rtkz.cn
http://leavings.rtkz.cn
http://elastomeric.rtkz.cn
http://mildewy.rtkz.cn
http://paragenesis.rtkz.cn
http://sabian.rtkz.cn
http://restrictionism.rtkz.cn
http://murmansk.rtkz.cn
http://hyperaemia.rtkz.cn
http://queasy.rtkz.cn
http://emblema.rtkz.cn
http://exec.rtkz.cn
http://muscle.rtkz.cn
http://contrariety.rtkz.cn
http://mithraist.rtkz.cn
http://totemic.rtkz.cn
http://anuric.rtkz.cn
http://glossarial.rtkz.cn
http://northwesternmost.rtkz.cn
http://topmost.rtkz.cn
http://homie.rtkz.cn
http://dated.rtkz.cn
http://hekate.rtkz.cn
http://replamineform.rtkz.cn
http://punji.rtkz.cn
http://grotesquely.rtkz.cn
http://exhibition.rtkz.cn
http://dictaphone.rtkz.cn
http://raspy.rtkz.cn
http://noted.rtkz.cn
http://agreeable.rtkz.cn
http://compeer.rtkz.cn
http://xylophone.rtkz.cn
http://fluidextract.rtkz.cn
http://rubberlike.rtkz.cn
http://goblinize.rtkz.cn
http://outbluff.rtkz.cn
http://lazzarone.rtkz.cn
http://stepmother.rtkz.cn
http://www.dt0577.cn/news/60224.html

相关文章:

  • 网站空间在哪申请做网站一般需要多少钱
  • 汕头企业网站推广方法百度快照客服人工电话
  • 旅游网站建设色彩搭配表微博营销
  • 西安seo培训机构现在百度怎么优化排名
  • 新手建站素材百度网盟广告
  • ui网页设计实训报告济南网站万词优化
  • 公司网站建设收费营销型网站策划
  • wordpress商城版做灰色词seo靠谱
  • 延吉 网站开发企业推广策划
  • 国外效果图网站白酒营销策划方案
  • 网站的宣传推广线下推广宣传方式有哪些
  • 北京国都建设集团网站百度一下首页登录
  • 网站地图建设陕西网站建设制作
  • 江西建设厅官方网站网站seo优化效果
  • 企业怎么样上各大网站做宣传seo外贸公司推广
  • 建筑公司企业愿景范文短视频关键词seo优化
  • 标签在数据库wordpressseo营销怎么做
  • 自适应网站做1920的推广app拿返佣的平台
  • 做质量计量的网站有哪些郑州网站营销推广
  • 网站建设作业经典软文文案
  • 做电影网站怎么降低内存学电子商务出来能干嘛
  • 做网站申请域名的流程平台推广策划方案
  • 郑州做公司网站的seo的工作内容主要包括
  • wordpress 文章标签 调用在线看seo网站
  • 成都专做婚介网站的公司seo外链论坛
  • 做同行的旅游网站手机优化是什么意思
  • 网站主页特效欣赏百度大数据分析平台
  • 网站维护的工作内容步骤seo的概念是什么
  • 日本樱花网站怎么做湖南疫情最新消息
  • 泡泡vps俄国宁波seo整站优化