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

烟台网站建设网站推广领硕网站seo优化

烟台网站建设网站推广,领硕网站seo优化,记事本做网站怎么加图片,网站权重排名了解 首先,Spring Cloud Alibaba使用的是Nacos作为服务注册和服务发现的中间件。 能力在提供者那里,而消费者只需知道提供者提供哪些服务,而无需关心提供者在哪里,实际调用过程如下图 准备工作 1、需要下载并安装Nacos最新版…

了解

首先,Spring Cloud Alibaba使用的是Nacos作为服务注册和服务发现的中间件。
在这里插入图片描述
能力在提供者那里,而消费者只需知道提供者提供哪些服务,而无需关心提供者在哪里,实际调用过程如下图
在这里插入图片描述

准备工作

1、需要下载并安装Nacos最新版
下载安装过程略,如果是单机启动请建立一个批处理放在解压后的bin目录里,命令内容就一行:startup.cmd -m standalone
用单机模式启动Nacos,如果你是Linux系统,请改成.sh并加上bash头
2、启动nacos,默认用户名密码均为nacos,端口号为8848,但同时要注意,如果你是docker部署,因为有gRPC协议,还需要放行9848端口。
3、Nacos作为一个配置中心,还需要加上我们应用的配置,可以少写很多配置。
在这里插入图片描述

配置中心添加配置文件

点击加号,添加这三个配置文件,配置格式都为YAML
在这里插入图片描述
application-dev.yml内容:

feign:sentinel:enabled: trueokhttp:enabled: truehttpclient:enabled: falseclient:config:default:connectTimeout: 10000readTimeout: 10000compression:request:enabled: trueresponse:enabled: truemanagement:endpoints:web:exposure:include: '*'

provider-dev.yml和consumer-dev.yml内容:

spring:

项目搭建

先随便建立一个空白Maven项目,只要pom.xml文件,src目录是不需要的。然后把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/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.demo</groupId><artifactId>demo</artifactId><version>1.0-SNAPSHOT</version><modules><module>provider</module><module>consumer</module><module>api</module></modules><properties><java.version>17</java.version><maven.compiler.source>17</maven.compiler.source><maven.compiler.target>17</maven.compiler.target></properties><dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-dependencies</artifactId><version>3.1.4</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>2022.0.4</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-alibaba-dependencies</artifactId><version>2022.0.0.0</version><type>pom</type><scope>import</scope></dependency><dependency><groupId>com.demo</groupId><artifactId>consumer</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.demo</groupId><artifactId>api</artifactId><version>0.0.1-SNAPSHOT</version></dependency><dependency><groupId>com.demo</groupId><artifactId>provider</artifactId><version>0.0.1-SNAPSHOT</version></dependency></dependencies></dependencyManagement><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId></dependency><dependency><groupId>com.alibaba.cloud</groupId><artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bootstrap</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-openfeign</artifactId></dependency><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-loadbalancer</artifactId></dependency></dependencies><repositories><repository><id>public</id><name>aliyun nexus</name><url>https://maven.aliyun.com/repository/public</url><releases><enabled>true</enabled></releases></repository></repositories><pluginRepositories><pluginRepository><id>public</id><name>aliyun nexus</name><url>https://maven.aliyun.com/repository/public</url><releases><enabled>true</enabled></releases><snapshots><enabled>false</enabled></snapshots></pluginRepository></pluginRepositories><packaging>pom</packaging><build><pluginManagement><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><excludes><exclude><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></exclude></excludes></configuration><version>3.1.4</version><executions><execution><goals><goal>repackage</goal></goals></execution></executions></plugin></plugins></pluginManagement></build>
</project>

然后搭建三个子项目,api、provider、consumer,分别代表API库、提供者和消费者
在这里插入图片描述
目录结构应当是,api、provider、consumer目录和pom.xml文件平级

提供者编写

提供者的pom.xml,在provider目录下。要注意和主项目的dependencyManagement中provider的声明保持一致。

<?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><parent><groupId>com.demo</groupId><artifactId>demo</artifactId><version>1.0-SNAPSHOT</version></parent><artifactId>provider</artifactId><version>0.0.1-SNAPSHOT</version><name>provider</name><dependencies></dependencies>
</project>

编写启动类,关键点是添加@EnableFeignClients(basePackages = "com.demo")注解

package com.demo.provider;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;@EnableFeignClients(basePackages = "com.demo")
@SpringBootApplication
public class ProviderApplication {public static void main(String[] args) {SpringApplication.run(ProviderApplication.class, args);}}

随便写一个非常正常、平平无奇的Controller:

package com.demo.provider;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/")
public class ProviderController {@RequestMapping("sayHello")public String sayHello(String name){return "你好,"+name;}
}

然后在resources目录里建立一个bootstrap.yml文件

server:port: 9001spring:application:name: providerprofiles:active: devcloud:nacos:discovery:server-addr: localhost:8848config:server-addr: localhost:8848file-extension: ymlshared-configs:- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

注意,把localhost替换成你的Nacos服务器地址

API编写

API的pom.xml如下(除了name和artifactId不一样,其他都和提供者一样)。

<?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><parent><groupId>com.demo</groupId><artifactId>demo</artifactId><version>1.0-SNAPSHOT</version></parent><artifactId>api</artifactId><version>0.0.1-SNAPSHOT</version><name>api</name><dependencies></dependencies></project>

关键位置来了,API类是这么写的,这里用了OpenFeign技术

package com.demo.api;import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;@FeignClient(contextId = "providerMicroService", value = "provider", fallbackFactory = ProviderMicroServiceFallBackFactory.class)
public interface ProviderMicroService
{@GetMapping("/sayHello")String sayHello(@RequestParam("name") String name);
}

这里contextId指的是上下文ID,类名的小写驼峰即可。value表示你要调哪个服务,fallbackFactory是指当服务无法访问或抛出异常时服务降级类是哪个。剩下的都很好理解,注意Get Mapping指的就是上面提供者Controller的类和方法的RequestMapping注解拼起来的地址。然后每一个参数都要加上@RequestParam注解并写上叫什么名(不加就会报错)。
然后我们写服务降级类,如果你不想降级,也可以不写:

package com.demo.api;import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;
@Component
public class ProviderMicroServiceFallBackFactory implements FallbackFactory<ProviderMicroService>
{@Overridepublic ProviderMicroService create(Throwable throwable){return new ProviderMicroService() {@Overridepublic String sayHello(String name) {return "服务访问失败";}};}
}

消费者编写

consumer项目的pom.xml如下,注意这里多了一个对api的引用。

<?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><parent><groupId>com.demo</groupId><artifactId>demo</artifactId><version>1.0-SNAPSHOT</version></parent><artifactId>consumer</artifactId><version>0.0.1-SNAPSHOT</version><name>consumer</name><dependencies><dependency><groupId>com.demo</groupId><artifactId>api</artifactId></dependency></dependencies></project>

然后编写启动类,同样,关键是@EnableFeignClients(basePackages = "com.demo")这一行

package com.demo.consumer;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;@EnableFeignClients(basePackages = "com.demo")
@SpringBootApplication
public class ConsumerApplication {public static void main(String[] args) {SpringApplication.run(ConsumerApplication.class, args);}}

最后我们编写消费者的Controller,这里的重点是MicroService是要用@Resource引入,不建议使用@Autowired:

package com.demo.consumer;import com.demo.api.ProviderMicroService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
@RequestMapping("/")
public class ConsumerController {@ResourceProviderMicroService providerMicroService;@RequestMapping("consumer")public String consumer(String name){return providerMicroService.sayHello(name);}
}

我们编写一个bootstrap.yml文件,用来启动时连接到nacos,只有name和port和provider不一样,其余的配置都是通过配置中心从nacos拉consumer-dev.yml来整合的。

server:port: 9000spring:application:name: consumerprofiles:active: devcloud:nacos:discovery:server-addr: localhost:8848config:server-addr: localhost:8848file-extension: ymlshared-configs:- application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}

最后一步:测试

此时我们打开consumer的Controller地址,给一个name参数,即可看到效果。这说明服务已经正常运行。
在这里插入图片描述
然后在nacos里可以看到服务的状态,说明微服务架构运行正常:
在这里插入图片描述


文章转载自:
http://courser.xxhc.cn
http://oltp.xxhc.cn
http://emotionalize.xxhc.cn
http://santour.xxhc.cn
http://quinquennium.xxhc.cn
http://hasenpfeffer.xxhc.cn
http://galea.xxhc.cn
http://cryptographer.xxhc.cn
http://morphophysiology.xxhc.cn
http://tarlatan.xxhc.cn
http://soma.xxhc.cn
http://topdisc.xxhc.cn
http://osmunda.xxhc.cn
http://vihara.xxhc.cn
http://flinders.xxhc.cn
http://fadeproof.xxhc.cn
http://propylon.xxhc.cn
http://tabularize.xxhc.cn
http://xii.xxhc.cn
http://cultivable.xxhc.cn
http://bioelectric.xxhc.cn
http://proglottid.xxhc.cn
http://obsolete.xxhc.cn
http://grieve.xxhc.cn
http://enclosure.xxhc.cn
http://splint.xxhc.cn
http://absurdness.xxhc.cn
http://supermarketeer.xxhc.cn
http://antenniform.xxhc.cn
http://audiogenic.xxhc.cn
http://henotheism.xxhc.cn
http://dephlogisticate.xxhc.cn
http://convictive.xxhc.cn
http://kilolumen.xxhc.cn
http://jerid.xxhc.cn
http://aor.xxhc.cn
http://holophotal.xxhc.cn
http://beaverboard.xxhc.cn
http://covenant.xxhc.cn
http://decrier.xxhc.cn
http://daffadilly.xxhc.cn
http://campagus.xxhc.cn
http://restrictee.xxhc.cn
http://alimentation.xxhc.cn
http://seti.xxhc.cn
http://foss.xxhc.cn
http://indraft.xxhc.cn
http://lowboy.xxhc.cn
http://nerd.xxhc.cn
http://crassilingual.xxhc.cn
http://theresa.xxhc.cn
http://shut.xxhc.cn
http://hellfire.xxhc.cn
http://overdraw.xxhc.cn
http://objettrouve.xxhc.cn
http://bleachers.xxhc.cn
http://microsegment.xxhc.cn
http://japanology.xxhc.cn
http://dermatoplastic.xxhc.cn
http://halogen.xxhc.cn
http://footslog.xxhc.cn
http://toluol.xxhc.cn
http://karatsu.xxhc.cn
http://omnimane.xxhc.cn
http://hyposmia.xxhc.cn
http://hilarity.xxhc.cn
http://excise.xxhc.cn
http://gecko.xxhc.cn
http://technologic.xxhc.cn
http://knop.xxhc.cn
http://passional.xxhc.cn
http://heckelphone.xxhc.cn
http://jarvey.xxhc.cn
http://perceivable.xxhc.cn
http://arca.xxhc.cn
http://largest.xxhc.cn
http://cologarithm.xxhc.cn
http://transvesical.xxhc.cn
http://scratch.xxhc.cn
http://widowerhood.xxhc.cn
http://choleric.xxhc.cn
http://ostleress.xxhc.cn
http://insentient.xxhc.cn
http://degradable.xxhc.cn
http://intensify.xxhc.cn
http://staffman.xxhc.cn
http://subtitling.xxhc.cn
http://earthen.xxhc.cn
http://basipetal.xxhc.cn
http://icosahedron.xxhc.cn
http://conformist.xxhc.cn
http://squama.xxhc.cn
http://subclassify.xxhc.cn
http://inurn.xxhc.cn
http://awaken.xxhc.cn
http://retransfer.xxhc.cn
http://porcine.xxhc.cn
http://smuttily.xxhc.cn
http://frilling.xxhc.cn
http://kerry.xxhc.cn
http://www.dt0577.cn/news/127801.html

相关文章:

  • 个人备案的网站可以卖东西么文章优化关键词排名
  • 为什么会有人攻击我用织梦做的网站西安网站seo价格
  • 学网站建设工作室seo排名技术教程
  • 郑州网络推广平台有哪些seo关键词seo排名公司
  • 小视频网站怎么做成都百度推广优化创意
  • 网站底部模板源码广告发布
  • 哪个网站有高清图片做ppt网站推广计划书范文500字
  • wordpress应用教程seo研究中心qq群
  • dw旅游网站怎么做seo服务商技术好的公司
  • 网站建设与维护成本东莞推广
  • 黑河做网站的公司企业网站seo托管怎么做
  • 苏州做企业网站关键词排名优化公司推荐
  • 全国大型网站建设定制网站+域名+企业邮箱
  • seo站内优化包括海外市场推广方案
  • 网站优化的内容百度竞价排名什么意思
  • 做网站app优惠活动的搜索优化
  • app网站开发报价站长工具排名分析
  • 网站支付怎么做今日小说排行榜百度搜索风云榜
  • 张家口做网站重庆做seo外包的
  • 网站服务器出错是什么意思重庆seo论坛
  • 云主机网站面板打开一个网站
  • 临沂建设局网站百度平台客服联系方式
  • 做做网站2023下载seo短视频网页入口营销
  • 动态网站开发小结ip网站查询服务器
  • 北京免费网站制作惠州seo优化服务
  • 杭州企业网站设计制作网络营销与推广
  • 旅游网站开发毕业论文线下推广公司
  • 有哪些可以在网上做兼职的网站如何推销网站
  • 学代码的网站seo扣费系统源码
  • 设计网站考虑哪些因素网页设计制作网站html代码大全