简介

jHipster 集成了springcloud的注册中心(eureka server)和配置中心(config server),eureka server 能够将我们自己开发的微服务(Microservices)都纳入到它自身当中,config server 能够集中管理应用程序各个环境下的配置,默认使用git 仓库存储配置内容。

Microservices没有前端页面,前端页面由网关产生(gateway),权限控制可以通过UAA进行管理,并且要在JHipster Registry中注册、发现和管理。

JHipster Registry 是微服架构必不可少的。它把所有的组件连接在一起,使他们能够互相通信。

Microservices 它只有后台代码。它更注重的是在API上。一个微服结构可以有许多微服应用,每个包含几个相关的实体和业务规则。

Gateway 它为所有微服务提供了HTTP路由和负载均衡,服务质量,安全和API文档。

UAA是一个使用OAuth2认证协议、为JHipster微服务提供用户账户和授权的服务。


file

微服务安装

安装JHipster Registry

由于 JHipster Registry 是一个标准的jhipster,所以我们只需要克隆下来运行它即可。没有必要打开idea或者修改它:

第一种方式
git clone https://github.com/jhipster/jhipster-registry
#cd到jhipster-registry文件夹,运行
mvnw

执行mvnw命令后,系统将自动编译运行。

第二种方式
git clone https://github.com/jhipster/jhipster-registry.git
# 编译启动
mvn clean package
java -jar target/jhipster-registry-*.war

打开https://localhost:8761/,并且登录,默认账户admin,密码admin。

Instances Registered是自动注册的服务,当我们创建服务后,将自动注册到这里

file

安装uaa

部署完jHipster registry ,我们需要创建一个用于控制访问权限的项目。

#创建文件夹存放项目
mkdir uaa
#切换到文件夹
cd uaa
#创建UAA服务
yo jhipster
#仅供参考
? (1/14) Which *type* of application would you like to create? [BETA] JHipster UAA server (for microservice OAuth2 authentication)
? (2/14) What is the base name of your application? uaa
? (3/14) Would you like to install other generators from the JHipster Market Place? No
? (3/14) 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. 9999
? (4/14) What is your default Java package name? cn.jhipter.uaa
? (5/14) Which Service Discovery and Configuration solution would you like to use? JHipster Registry (using Eureka and Spring Cloud Config)
? (6/14) Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle, MSSQL)
? (7/14) Which *production* database would you like to use? MySQL
? (8/14) Which *development* database would you like to use? MySQL
? (9/14) Do you want to use Hibernate 2nd level cache? Yes, with HazelCast (distributed cache, for multiple nodes)
? (10/14) Would you like to use Maven or Gradle for building the backend? Maven
? (11/14) Which other technologies would you like to use? (Press <space> to select, <a> to toggle all, <i> to inverse selection)
? (12/14) Would you like to enable internationalization support? Yes
#国际化支持,选择简体中文
? Please choose the native language of the application? Chinese (Simplified)
? Please choose additional languages to install (Press <space> to select, <a> to toggle all, <i> to inverse selection)
? (13/14) Which testing frameworks would you like to use? (Press <space> to select, <a> to toggle all, <i> to inverse selection)Gatling

通过mvnw编译启动项目

创建Microservices Application

操作同uaa

#创建文件夹存放项目
mkdir app
#切换到文件夹
cd app
#创建微服务
yo jhipster
#仅供参考
? (1/14) Which *type* of application would you like to create? Microservice application
? (2/14) What is the base name of your application? app
? (3/14) Would you like to install other generators from the JHipster Market Place? No
? (3/14) 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
? (4/14) What is your default Java package name? cn.jhipster.app
? (5/14) Which *type* of authentication would you like to use? [BETA] Authentication with JHipster UAA server (the server must be generated separately)
? (6/14) What is the folder path of your UAA application?. ../uaa
? (7/14) Which Service Discovery and Configuration solution would you like to use? JHipster Registry (using Eureka and Spring Cloud Config)
? (8/14) Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle)
? (9/14) Which *production* database would you like to use? MySQL
? (10/14) Which *development* database would you like to use? MySQL
? (11/14) Do you want to use Hibernate 2nd level cache? Yes, with HazelCast (distributed cache, for multiple nodes)
? (12/14) Would you like to use Maven or Gradle for building the backend? Maven
? (13/14) Which other technologies would you like to use? (Press <space> to select, <a> to toggle all, <i> to inverse selection)
? (14/14) Would you like to enable internationalization support? Yes
? Please choose the native language of the application? Chinese (Simplified)
? Please choose additional languages to install (Press <space> to select, <a> to toggle all, <i> to inverse selection)
? (15/14) Which testing frameworks would you like to use? (Press <space> to select, <a> to toggle all, <i> to inverse selection)Gatling

同样还需要修改数据库配置\src\main\resources\config\application-dev.yml,在application.yml中可以看到,系统已经自动帮我们注册了

file

启动项目(参考uaa)

创建网关(Gateway)

创建一个网关,用来做为所有请求的入口

#创建文件夹存放项目
mkdir gateway
#切换到文件夹
cd gateway
#创建微服务网关
yo jhipster
#仅供参考
? (1/14) Which *type* of application would you like to create? Microservice gateway
? (2/14) What is the base name of your application? gateway
? (3/14) Would you like to install other generators from the JHipster Market Place? No
? (3/14) 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
? (4/14) What is your default Java package name? cn.jhipster.gateway
? (5/14) Which *type* of authentication would you like to use? [BETA] Authentication with JHipster UAA server (the server must be generated separately)
? (6/14) What is the folder path of your UAA application?. ../uaa
? (7/14) Which Service Discovery and Configuration solution would you like to use? JHipster Registry (using Eureka and Spring Cloud Config)
? (8/14) Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle, MSSQL)
? (9/14) Which *production* database would you like to use? MySQL
? (10/14) Which *development* database would you like to use? MySQL
? (11/14) Do you want to use Hibernate 2nd level cache? Yes, with HazelCast (distributed cache, for multiple nodes)
? (12/14) Would you like to use Maven or Gradle for building the backend? Maven
? (13/14) Which other technologies would you like to use? (Press <space> to select, <a> to toggle all, <i> to inverse selection)
? (14/14) Would you like to use the LibSass stylesheet preprocessor for your CSS? No
? (15/14) Would you like to enable internationalization support? Yes
? Please choose the native language of the application? Chinese (Simplified)
? Please choose additional languages to install (Press <space> to select, <a> to toggle all, <i> to inverse selection)
? (16/14) Which testing frameworks would you like to use? (Press <space> to select, <a> to toggle all, <i> to inverse selection)Gatling

同样需要修改数据库配置并启动项目

file

打开 https://localhost:8761 ,就可以查看到我们创建的服务。 将它和网关服务进行对比,可以看出网关页面管理里面多了些菜单。

最后修改:2019 年 10 月 30 日 05 : 10 PM