您现在的位置是:首页 >其他 >(二)Jhipster 快速搭建微服务网站首页其他

(二)Jhipster 快速搭建微服务

想买CT5的小曹 2023-05-31 04:00:03
简介(二)Jhipster 快速搭建微服务

(一)Jhipster 的简介与安装https://blog.csdn.net/weixin_46085718/article/details/130282249

目录

 1、搭建注册中心 Jhipster registry

 2、使用 Jhipster 搭建微服务

 3、使用 Jhipster 搭建 gateway


1、搭建注册中心 Jhipster registry

Jhipster registry是一个基于spring cloud的配置中心。所有的微服务 APP 都需要注册到这里。 我们不需要手动的去创建这个项目,Jhipster 已经为我们准备好了

Jhipster-registryhttps://github.com/jhipster/jhipster-registry

首先创建一个 registry 文件夹,将注册中心代码 clone 至此,也可以安装 docker,然后 docker 安装注册中心也可以,这里介绍 git clone 方式,因为 docker 拉取很慢。

git clone https://github.com/jhipster/jhipster-registry.git

将项目导入到IDEA中进行运行,加载 pom 文件,maven 依赖。

 运行截图如下:

 运行成功,在进行注册中心管理页面查看。账号密码都是 admin

http://localhost:8761/

 这里包含了系统状态、详情、注册在注册中心的实例、健康情况等

 并且可以查看 Swagger-ui

 2、使用 Jhipster 搭建微服务

(1)建立一个空的文件夹,cmd运行 jhipster

jhipster

第一个问题:询问需要创建什么类型的应用,普通项目、网关应用、微服务应用

 其他问题如下:

可以按照下面给出的进行回答,参考

Welcome to JHipster v7.9.3

Application files will be generated in folder: G:	estProduct
 _______________________________________________________________________________________________________________

  Documentation for creating an application is at https://www.jhipster.tech/creating-an-app/
  If you find JHipster useful, consider sponsoring the project at https://opencollective.com/generator-jhipster
 _______________________________________________________________________________________________________________

? Which *type* of application would you like to create? Microservice application
? Do you want to enable *microfrontends*? No
? What is the base name of your application? Product
? Do you want to make it reactive with Spring WebFlux? No
? As you are running in a microservice architecture, on which port would like your server to run? It should be unique to
 avoid port conflicts. 8081
? What is your default Java package name? com.mycompany.myapp
? Which service discovery server do you want to use? JHipster Registry (uses Eureka, provides Spring Cloud Config
support and monitoring dashboards)
? Which *type* of authentication would you like to use? JWT authentication (stateless, with a token)
? Which *type* of database would you like to use? SQL (H2, PostgreSQL, MySQL, MariaDB, Oracle, MSSQL)
? Which *production* database would you like to use? MySQL
? Which *development* database would you like to use? MySQL
? Which cache do you want to use? (Spring cache abstraction) Redis (distributed cache)
? Do you want to use Hibernate 2nd level cache? Yes
? Would you like to use Maven or Gradle for building the backend? Maven
? Which other technologies would you like to use?
? Would you like to enable internationalization support? Yes
? Please choose the native language of the application Chinese (Simplified)
? Please choose additional languages to install
? Besides JUnit and Jest, which testing frameworks would you like to use?
? Would you like to install other generators from the JHipster Marketplace? No

项目创建完成之后,即可导入到 IDEA 里面运行,需要修改yml配置文件,首先数据库配置,然后是注册中心配置,同一台电脑不用进行修改。

 完整项目结构:

 登录注册中心可以看到两个服务都已经注册上,说明配置没有问题。

 3、使用Jhipster搭建 gateway

创建一个文件夹 gateway,使用命令 jhipster 即可。

? Which *type* of application would you like to create? Gateway application
? Do you want to enable *microfrontends*? No
? What is the base name of your application? gateway
? As you are running in a microservice architecture, on which port would like your server to run? It should be unique to
 avoid port conflicts. 8080
? What is your default Java package name? com.mycompany.myapp
? Which service discovery server do you want to use? JHipster Registry (uses Eureka, provides Spring Cloud Config
support and monitoring dashboards)
? Which *type* of authentication would you like to use? JWT authentication (stateless, with a token)
? Which *type* of database would you like to use? SQL (H2, PostgreSQL, MySQL, MariaDB, Oracle, MSSQL)
? Which *production* database would you like to use? MySQL
? Which *development* database would you like to use? MySQL
? Which cache do you want to use? (Spring cache abstraction) Redis (distributed cache)
? Do you want to use Hibernate 2nd level cache? Yes
? Would you like to use Maven or Gradle for building the backend? Maven
? Which other technologies would you like to use?
? Which *Framework* would you like to use for the client? Vue
? Do you want to generate the admin UI? Yes
? Would you like to use a Bootswatch theme (https://bootswatch.com/)? Default JHipster
? Would you like to enable internationalization support? Yes
? Please choose the native language of the application Chinese (Simplified)
? Please choose additional languages to install
     info Disabling hibernate cache for cache provider no
? Besides JUnit and Jest, which testing frameworks would you like to use?
? Would you like to install other generators from the JHipster Marketplace? No

按照上面步骤即可搭建网关,创建完成。

 修改相关的数据库配置及注册中心配置,在注册中心可以看到注册成功。

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。