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

免费建网站样板手机版充电宝seo关键词优化

免费建网站样板手机版,充电宝seo关键词优化,濮阳做网站,微信网站小游戏下面写一个简单的demo验证下eureka&#xff0c;实现服务注册、服务发现。 一、单节点&#xff1a; 1、api&#xff1a; 封装其他组件需要共用的dto 2、eureka-service服务注册中心&#xff1a; &#xff08;1&#xff09;pom: <?xml version"1.0" encoding&q…

 下面写一个简单的demo验证下eureka,实现服务注册、服务发现。

一、单节点:

1、api:

封装其他组件需要共用的dto

2、eureka-service服务注册中心:

(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"><modelVersion>4.0.0</modelVersion><groupId>com.demo.cloud</groupId><artifactId>myspringcloud-eureka-server</artifactId><version>1.0-SNAPSHOT</version><!-- springBoot --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.9.RELEASE</version></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>Edgware.RELEASE</spring-cloud.version></properties><dependencies><!--eureka-server--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka-server</artifactId></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><repositories><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/libs-milestone</url><snapshots><enabled>false</enabled></snapshots></repository></repositories></project>

 (2)application.properties:在默认设置下,该服务注册中心也会将自己作为客户端来尝试注册它自己,所以需要禁用它的客户端注册行为

server.port=1111
eureka.client.registerWithEureka=false  
eureka.client.fetchRegistry=false  
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/

(3)启动类:

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

启动后,访问http://localhost:1111/:

就可以从后台监控服务了,(是不是比dubbo搭建zk注册中心方便多了) ,此时还没有服务注册过来,可以看到application下是空的。

3、eureka-client注册服务提供者:将原有的springboot工程改造,注册到eureka注册中心

(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"><modelVersion>4.0.0</modelVersion><groupId>com.demo.cloud</groupId><artifactId>myspringcloud-eureka-client</artifactId><version>1.0-SNAPSHOT</version><!-- springBoot --><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>1.5.9.RELEASE</version></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version><spring-cloud.version>Edgware.RELEASE</spring-cloud.version></properties><dependencies><!--eureka-server--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-eureka-server</artifactId></dependency><dependency><groupId>com.demo.cloud.api</groupId><artifactId>myspringcloud-api</artifactId><version>1.0-SNAPSHOT</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!-- mybatis --><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.1.1</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>5.1.21</version></dependency><dependency><groupId>commons-collections</groupId><artifactId>commons-collections</artifactId><version>3.2.1</version></dependency><dependency><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId><version>2.5</version></dependency></dependencies><dependencyManagement><dependencies><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-dependencies</artifactId><version>${spring-cloud.version}</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><repositories><repository><id>spring-milestones</id><name>Spring Milestones</name><url>https://repo.spring.io/libs-milestone</url><snapshots><enabled>false</enabled></snapshots></repository></repositories></project>

(2)application.properties:

server.port=2222
server.context-path=/myService
spring.application.name=my-service
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/#mybatis
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/demo?useUnicode=true&characterEncoding=utf-8&useSSL=false
spring.datasource.username=root
spring.datasource.password=wtyy
mybatis.mapper-locations=classpath*:Mapper/*Mapper.xml

(3)dao、service、Mapper:mybatis持久化部分,此处省略

(4)controller:

package com.demo.cloud.controller;import com.demo.cloud.dto.AuthorityDTO;
import com.demo.cloud.dto.UserDTO;
import com.demo.cloud.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import java.util.List;@RequestMapping("/user")
@RestController
public class UserApiController {@Autowiredprivate UserService userService;@Value("${server.port}")private String port;@RequestMapping("/findByUserName")public UserDTO findByUserName(String username){return userService.findByUserName(username);}@RequestMapping("/getAllUsers")public List<UserDTO> getAllUsers(){System.out.println(port);return userService.getAllUsers();}@RequestMapping("/getAuthortiesByUserId")public List<AuthorityDTO> getAuthortiesByUserId(Integer userId){return userService.getAuthortiesByUserId(userId);}@RequestMapping("/addUser")public void addUser1(@RequestBody UserDTO userDTO){userService.addUser(userDTO);}}

(5)启动类:

package com.demo.cloud;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;@SpringBootApplication
@EnableEurekaClient
@MapperScan("com.demo.cloud.dao")
public class MyEurekaClientApplication {public static void main(String args[]){SpringApplication.run(MyEurekaClientApplication.class,args);}
}

注意:这里使用的是@EnableEurekaClient注解,也可以使用@EnableDiscoveryClient注解, 

@EnableEurekaClient是Eureka特有的注解,用于启动Eureka客户端。当使用Eureka作为注册中心时,就推荐使用@EnableEurekaClient注解,应用启动后会自动注册到Eureka Server,并完成服务治理。
@EnableDiscoveryClient是Spring Cloud通用的注解,可以与Eureka、Consul等多种注册中心对接。当我们的微服务同时需要与多个注册中心集成时,就需要使用@EnableDiscoveryClient注解。
可以说,@EnableEurekaClient是@EnableDiscoveryClient的一个具体实现,如果项目中注册中心只使用Eureka,那么使用@EnableEurekaClient更加方便和简单。但如果要切换到其他的注册中心,改动较大。

启动项目,再浏览下http://localhost:1111/:

可以看到注册成功了。

二、高可用部署:

1、先部署eukera-service的高可用

2、再部署eureka-client的高可用:连接注册中心的配置项改为多个,以逗号分隔,然后将该组件部署多个节点即可

eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/,http://xxx.xx.xxx:1111/eureka/

http://www.ds6.com.cn/news/29354.html

相关文章:

  • 壹财富 网站开发今日头条新闻推荐
  • 社区营销优化 保证排名
  • 北京网站开发人员网站排名优化培训
  • 网站首页的图标是怎么做的上海关键词排名优化价格
  • 网页设计与网站建设是干嘛的seo整站网站推广优化排名
  • 保定市人民政府网站南京百度关键字优化价格
  • 专门做婚姻法的网站站长资讯
  • 网站开发是前端还是后端营业推广的方式
  • 未来网站发展方向今日要闻新闻
  • excel连接网站 做数据分析推广普通话活动方案
  • 外贸网站 站长工具百度手机下载安装
  • 网站建立好如何做seo网站名查询网址
  • java视频播放网站开发seo技术团队
  • 安联建设集团股份公司网站东莞疫情最新通知
  • 中小企业融资服务平台兰州搜索引擎优化
  • 网站建设首选易网宣app下载注册推广平台
  • 自动全屏网站模板合肥瑶海区
  • 网站 设计 文档免费seo推广软件
  • 线上网站设计成都seo顾问
  • 网购网站建设关键词seo优化
  • 广州铁路投资建设集团网站创意设计
  • 用于网站建设的费用怎么备注现在网络推广哪家好
  • 站内内容投放计划如何做好互联网营销推广
  • wordpress ie很慢台州seo公司
  • 网站宣传虚假处罚标准营销推广网
  • 百度上如何创建自己的网站盘多多网盘资源库
  • 梁定然网页设计教程长春百度seo排名
  • 360建站工具关键词简谱
  • adobe 做网站宁波seo关键词费用
  • 企业网络营销策略分析案例百度手机端排名如何优化