准备
从Oracle网站安装Java 8。
从Node.js网站安装Node.js(LTS 64位版本,不支持非LTS版本)。
如使用docker,请从docker网站安装docker。
安装JHipster
使用yarn安装,在终端运行:
yarn add global generator-jhipster
使用npm安装,在终端运行:
npm install -g generator-jhipster
等待安装完毕,执行jhipster --version
,你将会看到版本信息。
生成应用
在此之前,可以先准备一个github repository(仓库),之后将在这个仓库上创建许多Git Branchs(分支)。
可以查看本博客关于Git简要说明。
准备工作区
为工作区创建一个新文件夹,导航到该文件夹。
mkdir my-test-app
cd my-test-app
为应用创建一个文件夹,导航到该文件夹。
mkdir my-shop
cd my-shop
在开始前执行jhipster --version
确保准备完成,最好使用最新版本的工具,执行yarn global upgrade generator-jhipster
或npm update -g generator-jhipster
更新版本。
使用JHipster生成代码
生成代码只需要在应用文件夹下终端执行jhipster
命令,终端将输出。
JHipster将询问一些问题,以获得有关所需的不同选项输入。
? (1/19) Which *type* of application would you like to create? (Use arrow keys) //选择创建的应用类型
> Monolithic application (recommended for simple projects) //综合应用
Microservice application //微服务应用
Microservice gateway //微服务网关
[BETA] JHipster UAA server (for microservice OAuth2 authentication) //微服务OAuth2的身份认证服务
服务器选择
? (2/19) What is the base name of your application? (shop) //服务名
? (3/19) What is your default Java package name? (com.mycompany.app) //默认包名
? (4/19) ? Do you want to use the JHipster Registry to configure, monitor and scale your application? (Use arrow keys) //微服务注册中心和统一配置中心,只有在微服务架构时才会使用
> No
Yes
? (5/19) Which *type* of authentication would you like to use? (Use arrow keys) //选择认证方式
> JWT authentication (stateless, with a token) //使用JSON Web Token
OAuth 2.0 / OIDC Authentication (stateful, works with Keycloak and Okta) //使用OpenID连接服务,类似于Keycloak或者Okta
HTTP Session Authentication (stateful, default Spring Security mechanism) //经典的基于session认证的机制
Authentication with JHipster UAA server // 此种方式必须提前生成JHipster UAA Server (Q1的选项),它是基于OAuth2的验证服务
? (6/19) Which *type* of database would you like to use? (Use arrow keys) //选择数据库类型
> SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle, MSSQL) //关系型数据库
MongoDB
Couchbase
Cassandra
? (7/19) Which *production* database would you like to use? //生产数据库
MySQL
MariaDB
> PostgreSQL
Oracle (Please follow our documentation to use the Oracle proprietary driver)
Microsoft SQL Server
? (8/19) Which *development* database would you like to use? //开发数据库
H2 with disk-based persistence //数据存储在磁盘的H2
H2 with in-memory persistence //内存H2(服务关闭数据丢失)
> PostgreSQL
? (9/19) Do you want to use the Spring cache abstraction?
Yes, with the Ehcache implementation (local cache, for a single node) //本地缓存方案 ehcache
> Yes, with the Hazelcast implementation (distributed cache, for multiple nodes) //集群缓存方案,多节点缓存,适合多微服务的分布式环境
[BETA] Yes, with the Infinispan implementation (hybrid cache, for multiple nodes)
Yes, with Memcached (distributed cache) - Warning, when using an SQL database, this will disable the Hib
ernate 2nd level cache!
No - Warning, when using an SQL database, this will disable the Hibernate 2nd level cache!
? (10/19) Do you want to use Hibernate 2nd level cache? (Y/n) y //Hibernate 二级缓存
? (11/19) Would you like to use Maven or Gradle for building the backend? //选择后台构建系统
Maven //更成熟,稳定,用户群体更大
> Gradle //更灵活,易于扩展,支持maven一键转Gradle
? (12/19) Which other technologies would you like to use? //可选技术
( ) Search engine using Elasticsearch //集成搜索开源搜索引擎 ElasticSearch
>(*) WebSockets using Spring Websocket //使用Spring WebSocket、SocketJS和Stomp协议添加WebSocket支持
( ) Asynchronous messages using Apache Kafka //使用Kafka添加对异步队列的支持
( ) API first development using OpenAPI-generator //添加Swagger codegen对API优先开发的支持
客户端选择
? (13/19) Which *Framework* would you like to use for the client? (Use arrow keys) //客户端框架
> Angular
React
? (14/19) Would you like to enable *SASS* stylesheet preprocessor? (Y/n) y //SASS支持
国际化选择
? (15/19) Would you like to enable internationalization support? (Y/n) y //是否使用国际化
? (16/19) Please choose the native language of the application (Use arrow keys) //选择本地化语言
Belorussian
Bengali
Catalan
> Chinese (Simplified)
Chinese (Traditional)
Czech
Danish
(Move up and down to reveal more choices)
? (17/19) Please choose additional languages to install //选择其余支持语言
( ) Czech
( ) Danish
( ) Dutch
>(*) English
( ) Estonian
( ) Farsi
( ) French
(Move up and down to reveal more choices)
测试选择
? (18/19) Besides JUnit and Jest, which testing frameworks would you like to use? //应用程序选择测试选项
( ) Gatling
( ) Cucumber
>(*) Protractor
其他
? (19/19) Would you like to install other generators from the JHipster Marketplace? (y/N) n //是否需要去JHipster商城安装第三方插件模块
生成成功
运行
执行./gradlew
,相当于执行./gradlew bootRun -Pdev
。
该应用程序已经成功启动,可以在 http://localhost:8080 上查看。
测试
服务端测试
运行./gradlew test
,如果运行成功,将会看到BUILD SUCCESSFUL
。
客户端测试
运行npm test
或运行yarn test
。
e2e测试,需确保服务端正在运行,然后在运行npm e2e
或yarn e2e
。
热启动
在一个终端中,通过运行./gradlew
以dev模式启动服务器,在另一个终端中,通过运行yarn start
或npm start
启动客户端开发服务器。
当您在服务器端进行任何更改时,只需运行./gradlew compileJava
,或者如果您使用IDE,则单击compile按钮。
提交Git(可选择行执行)
> git init
> git add --all
> git commit -am "generated myshop application"