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

闸北区网站建设网页沈阳建设网站建站

闸北区网站建设网页,沈阳建设网站建站,青县做网站价格,视频号下载器手机版一、使用openfeig调用远程另外一个服务接口 1、创建一个spring boot工程,并且创建2个模块来当微服务模块 2、分别配置2个模块的启动文件 3、分别两个模块下创建一个测试的控制器 4、在项目的根目录的pom.xml中添加spring-cloud配置 propertiesjava.version1…一、使用openfeig调用远程另外一个服务接口 1、创建一个spring boot工程,并且创建2个模块来当微服务模块 2、分别配置2个模块的启动文件 3、分别两个模块下创建一个测试的控制器 4、在项目的根目录的pom.xml中添加spring-cloud配置 propertiesjava.version1.8/java.versionspring-cloud.version2021.0.8/spring-cloud.version /propertiesdependencyManagementdependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-dependencies/artifactIdversion${spring-cloud.version}/versiontypepom/typescopeimport/scope/dependency/dependencies /dependencyManagement5、在需要调用别的服务的项目中添加依赖 !-- 远程调用的包 -- dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-openfeign/artifactId /dependency dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-loadbalancer/artifactId /dependency6、在需要调用别的 服务的项目中创建一个文件夹feign里面创建一个文件SystemFeignHello.java的接口 package com.example.feign;import org.springframework.cloud.openfeign.FeignClient; import org.springframework.web.bind.annotation.GetMapping;FeignClient(name system, url http://localhost:9001/system) public interface SystemFeignHello {/*** 别的地方调用hell1方法的时候就会调用http://localhost:9001/system/hello路由* return*/GetMapping(hello)String hello1(); }7、测试调用另外一个服务的接口 package com.example.controller;import com.example.feign.SystemFeignHello; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;RestController public class HelloController {ResourceSystemFeignHello systemFeignHello;GetMapping(hello)public String hello() {return File Hello;}GetMapping(systemHello)public String getHello() {String helloResult this.systemFeignHello.hello1();System.out.println(helloResult返回数据);return helloResult;} }8、在调用服务的启动类上加上扫描注解 package com.example;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.openfeign.EnableFeignClients;SpringBootApplication EnableFeignClients(com.example.feign) public class FileApplication {public static void main(String[] args) {SpringApplication.run(FileApplication.class, args);}}9、网页上测试调用接口 10、system项目中接口如下,和普通接口没任何区别 package com.example.controller;import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;RestController public class HelloController {GetMapping(hello)public String hello() {return System Hello11;} }二、使用eureka来服务端配置 1、eureka分为服务端和客户端需要在项目中先创建一个eureka的服务段,在子项目中使用客户端的方式连接 2、创建一个eureka模块来做服务端 3、在eureka模块中添加依赖包 dependenciesdependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-server/artifactId/dependency /dependencies4、配置文件中基本配置 spring.application.nameeureka server.port8761 eureka.client.fetch-registryfalse eureka.client.register-with-eurekafalse5、在启动类上添加注解 package com.example;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;SpringBootApplication EnableEurekaServer public class EurekaApplication {public static void main(String[] args) {SpringApplication.run(EurekaApplication.class, args);}}6、直接在浏览器上输入http://localhost:8761/如下就表示配置成功 三、客户端配置 1、引入依赖包 !-- 客户端端 -- dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId /dependency2、在配置文件中添加 eurec.client.server-url.defaultZonehttp://localhost:8761/eureka/3、在启动文件中添加 SpringBootApplication EnableEurekaClient public class SystemApplication {public static void main(String[] args) {SpringApplication.run(SystemApplication.class, args);}}4、刷新浏览器查看服务是否已经注册成功 四、网关的配置 1、创建一个网关模块 2、在网关中引入依赖包 dependencies!-- 网关依赖 --dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-gateway/artifactId/dependency!-- 客户端端 --dependencygroupIdorg.springframework.cloud/groupIdartifactIdspring-cloud-starter-netflix-eureka-client/artifactId/dependency /dependencies3、修改配置文件 server.port8000 spring.application.namegateway server.servlet.context-path/gateway spring.main.web-application-typereactive eurec.client.server-url.defaultZonehttp://localhost:8761/eureka/# 注册一个服务 spring.cloud.gateway.routes[0].idsystem spring.cloud.gateway.routes[0].uri.http://localhost:9001 spring.cloud.gateway.routes[0].predicates[0].namePath spring.cloud.gateway.routes[0].predicates[0].args[0]/system/** # 注册一个服务 spring.cloud.gateway.routes[1].idfile spring.cloud.gateway.routes[1].uri.http://localhost:9000 spring.cloud.gateway.routes[1].predicates[0].namePath spring.cloud.gateway.routes[1].predicates[0].args[0]/file/**4、启动文件 package com.example;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient;SpringBootApplication EnableEurekaClient public class GatewayApplication {public static void main(String[] args) {SpringApplication.run(GatewayApplication.class, args);}}5、使用网关的地址直接访问别的路由http://localhost:8000/system/hello
http://www.hkea.cn/news/14295247/

相关文章:

  • 扬中网站推广世界500强公司排行榜
  • 河南省住房与城乡建设厅网站网站空间价格怎么算
  • 一个网站多个域名备案安徽工程建设信息网站
  • 网站招聘顾问做啥的社区门户网站建设方案
  • 学仿网站怎样做微商网站
  • 杭州住房和城乡建设部网站营销行网站建设
  • 免费建立个人网站官网企业网站建设哪家效果好
  • 做外贸网站咨询炫酷的国外网站
  • 建设网站的虚拟主机在哪里买网站换空间怎么换
  • 东莞市建设监督网站首页网站公司网站建设
  • 深圳网站建设多少钱学校网站织梦源码
  • 上鼎工程建设有限公司网站网页界面模板下载
  • 重庆建网站流程厦门关键词排名优化
  • 用wordpress做站群wordpress评论添加表情
  • wordpress 错位seo+网站排名
  • 网站建设需要入无形资产吗品质好的形容词
  • 个人网站icp备案教程一级造价工程师教材
  • dw软件网站建设教程视频软文营销写作技巧
  • 玄武建设局网站外链在线生成
  • 网站建设彩票做海报的软件app免费
  • 山西网站开发广州科技公司有哪些
  • 重庆专业网站公司龙岗区黄阁坑社区
  • 仙桃做网站的公司黄山新洲建设集团网站
  • 做西式快餐店网站广告传媒公司哪家好
  • 福建省建设厅网站信用评分雄安优秀网站建设
  • 移动互联网 网站建设济宁优化公司
  • 赣州网站建设优化服务手机网站制作招聘
  • 网页设计制作网站成品做网站南昌
  • 上海平台网站建设报价wordpress自动评论软件
  • 织梦个人网站西安外贸网站建设公司