JHispter的安装、使用

前言

参考:https://jhipster.github.io/installation
后台服务只生成带UAA的微服务
前端我们使用Angular,不使用AngularJS

安装

本地安装(yarn方式)

  • Install Java 8 from the Oracle website.
  • (Optional) Install a Java build tool.
    Whether you choose to use Maven or Gradle, you normally don’t have to install anything, as JHipster will automatically install the Maven Wrapper or the Gradle Wrapper for you.
    If you don’t want to use those wrappers, go to the official Maven website or Gradle website to do your own installation.
  • Install Git from git-scm.com.
    We recommend you also use a tool like SourceTree if you are starting with Git.
  • Install Node.js from the Node.js website (prefer an LTS version)
  • Install Yarn from the Yarn website
  • Install Yeoman:
    $ yarn global add yo
  • Install JHipster
$ yarn global add generator-jhipster
$ yarn global add generator-jhipster-elasticsearch-reindexer

使用

生成UAA

$ mkdir uaa
$ cd uaa
$ jhipster

? (1/16) Which *type* of application would you like to create? 
[BETA] JHipster UAA server (for microservice OAuth2 authentication)
? (2/16) What is the base name of your application? 
uaa
? (3/16) 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/16) What is your default Java package name? 
com.example.uaa
? (5/16) Do you want to use the JHipster Registry to configure, monitor and scale your microservices and gateways? 
Yes
? (6/16) Which *type* of database would you like to use? 
SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle, MSSQL)
? (7/16) Which *production* database would you like to use? 
MySQL
? (8/16) Which *development* database would you like to use? 
MySQL
? (9/16) Do you want to use Hibernate 2nd level cache? 
Yes, with HazelCast (distributed cache, for multiple nodes)
? (10/16) Would you like to use Maven or Gradle for building the backend? 
Maven
? (11/16) Which other technologies would you like to use?
? (12/16) Would you like to enable internationalization support? 
Yes
? Please choose the native language of the application 
Chinese (Simplified)
? Please choose additional languages to install
? (13/16) Besides JUnit and Karma, which testing frameworks would you like to use?
? (14/16) Would you like to install other generators from the JHipster Marketplace? 
No 

生成Gateway

在uaa的目录下

$ cd ..
$ mkdir gate
$ cd gate
$ jhipster --skip-client

? (1/16) Which *type* of application would you like to create? 
Microservice gateway
? (2/16) What is the base name of your application? 
gate
? (3/16) 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/16) What is your default Java package name? 
com.example.uaa
? (5/16) Do you want to use the JHipster Registry to configure, monitor and scale your microservices and gateways? 
Yes
? (6/16) Which *type* of authentication would you like to use? 
[BETA] Authentication with JHipster UAA server (the server must be generated separately)
? (7/16) What is the folder path of your UAA application? 
../uaa
? (8/16) Which *type* of database would you like to use? 
SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle)
? (9/16) Which *production* database would you like to use? 
MySQL
? (10/16) Which *development* database would you like to use? 
MySQL
? (11/16) Would you like to use Maven or Gradle for building the backend? 
Maven
? (12/16) Which other technologies would you like to use?
? (13/16) Which *Framework* would you like to use for the client? 
Angular 4
? (14/16) Would you like to use the LibSass stylesheet preprocessor for your CSS? 
No
? (15/16) Would you like to enable internationalization support? 
Yes
? Please choose the native language of the application 
Chinese (Simplified)
? Please choose additional languages to install
? (16/16) Besides JUnit and Karma, which testing frameworks would you like to use?
? (17/16) Would you like to install other generators from the JHipster Marketplace? 
No 

生成微服务

在uaa目录下

$ cd ..
$ mkdir app
$ cd app
$ jhipster

? (1/16) Which *type* of application would you like to create? 
Microservice application
? (2/16) What is the base name of your application? 
app
? (3/16) 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/16) What is your default Java package name? 
com.example.uaa
? (5/16) Do you want to use the JHipster Registry to configure, monitor and scale your microservices and gateways? 
Yes
? (6/16) Which *type* of authentication would you like to use? 
[BETA] Authentication with JHipster UAA server (the server must be generated separately)
? (7/16) What is the folder path of your UAA application? 
../uaa
? (8/16) Which *type* of database would you like to use? 
SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle)
? (9/16) Which *production* database would you like to use? 
MySQL
? (10/16) Which *development* database would you like to use? 
MySQL
? (11/16) Do you want to use Hibernate 2nd level cache? Yes, with 
HazelCast (distributed cache, for multiple nodes)
? (12/16) Would you like to use Maven or Gradle for building the backend? 
Maven
? (13/16) Which other technologies would you like to use?
? (14/16) Would you like to enable internationalization support? 
Yes
? Please choose the native language of the application 
Chinese (Simplified)
? Please choose additional languages to install
? (15/16) Besides JUnit and Karma, which testing frameworks would you like to use?
? (16/16) Would you like to install other generators from the JHipster Marketplace? 
No 
  1. 生成微服务中的Entity
jhipster  entity Organization --skip-client 

其中Organization是实体Entity的名字,可以替换成任意有有意义的其他实体名字

运行(以Docker的方式)

  • 启动registry
$ cd uaa
$ docker-compose -f src/main/docker/jhipster-registry.yml up -d 

启动成功后登陆
http://your-server:8761
默认用户名密码:admin/admin123

  • 启动UAA
$ cd uaa
$ ./mvnw package -Pdev docker:build
$ docker run -d --restart=always -p 9999:9999 -p 9999+5701:9999+5701  --name uaa  uaa
  • 启动GATE
    “`
    cdgate ./mvnw package -Pdev docker:build
    $ docker run -d –restart=always -p 8080:8080 -p 8080+5701:8080+5701 –name gate gate
 - 启动微服务APP 
  ```
$ cd app
$ ./mvnw package -Pdev docker:build
$ docker run -d --restart=always -p 8081:8081 -p 8081+5701:8081+5701  --name app  app
  • 启动后台管理
$ cd gate
$ yarn install
$ yarn start

按照输出的提示,在浏览器输入URL,注意端口。即可用admin/admin登陆后台管理界面

  • 更改webpack-dev-server域名

修改webpack.config.js,添加host,disableHostCheck选项
若后台管理和gate服务不在一台(虚拟)机器上,则需要修改webpack/webpack.dev.js或webpack/webpack.prod.js,增加host和disableHostCheck等配置

devServer: {
    historyApiFallback: true,
    host: '0.0.0.0',
    disableHostCheck: true,
    noInfo: true
  },
  • 生成数据实体Entity

进入工程根目录,运行

$ jhipster entity <entityName>
  • 登录API

API: http://localhost:9001/uaa/oauth/token

$ curl  http://ip:9001/uaa/oauth/token --request POST --insecure --data "grant_type=password&username=admin&password=admin" -H "Authorization:Basic d2ViX2FwcDo="

返回下面内容表示成功

{
  "access_token" : "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE1MDUwMTMxNTQsInVzZXJfbmFtZSI6ImF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H2iwOWRrkex2J7pe0uOFLuycQrgy4RsWSidrgl3uyWArZ0Q5q6bsm0be0PgQm45nBL6SVXOXz-WH3ZgslqPawoR2fCEfCCSz3-X15TmIofs30cDXq8A_N9FcJ5S5WfM555bVK0FbfW2_7BxwcTNg",
  "expires_in" : 43199,
  "scope" : "openid",
  "jti" : "6565fd30-8a14-4dc3-bba4-91c8d16c7ac4"
}

Elastic Search Reindex

yo generator-jhipster-elasticsearch-reindexer 

执行会提示

/opt/node-v8.4.0-linux-x64/lib/node_modules/yo/node_modules/insight/node_modules/configstore/index.js:53
                                throw err;
                                ^

Error: EACCES: permission denied, open '/root/.config/configstore/insight-yo.json'
You don't have access to this file.

    at Object.fs.openSync (fs.js:652:18)
    at Object.fs.readFileSync (fs.js:553:33)
    at Configstore.get (/opt/node-v8.4.0-linux-x64/lib/node_modules/yo/node_modules/insight/node_modules/configstore/index.js:34:26)
    at Configstore.get (/opt/node-v8.4.0-linux-x64/lib/node_modules/yo/node_modules/insight/node_modules/configstore/index.js:81:13)
    at Insight.get (/opt/node-v8.4.0-linux-x64/lib/node_modules/yo/node_modules/insight/lib/index.js:48:22)
    at Object.<anonymous> (/opt/node-v8.4.0-linux-x64/lib/node_modules/yo/lib/cli.js:194:47)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)

修改方案:

sed -i -e '/rootCheck/d' "${NPM_CONFIG_PREFIX}/lib/node_modules/yo/lib/cli.js"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值