創建一個簡單的Jhipster Demo , 根據以下步驟可完成簡單創建:
1. 創建註冊中心:
Jhipster官方提供註冊中心的源碼代碼,可以直接運行, 官方註冊中心地址:https://github.com/jhipster/jhipster-registry.git
git clone https://github.com/jhipster/jhipster-registry.git #根據官方提供的地址克隆文件到本地
文件夾
# 文件成功克隆到本地文件夾後, 進入該文件夾並按順序執行以下命令:
yarn install #安裝後端依賴
yarn start #編譯完成後運行Angular項目
mvnw # 運行後臺
在clone 註冊中心的源碼代碼時,可能速度很慢,慢慢等待吧! 當你執行 mvnw 命令並且後臺成功啓動後,可在http://localhost:8761/ 即可看到運行情況,具體效果圖如下:
2. 創建 uaa:
JHipster UAA是一種用戶會計和授權服務,用於使用OAuth2授權協議保護JHipster微服務。
mkdir uaa #創建一個新的目錄, 這裏uaa是目錄名稱,可進行自定義
cd uaa #進入剛創建的新目錄
jhipster #執行jhipster 命令
# 後面會出現這些問題,可根據自己的需求進行選擇
? Which *type* of application would you like to create? JHipster UAA server (for
microservice OAuth2 authentication) #微服務OAuth2的身份認證服務
? What is the base name of your application? uaa #名稱
?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 #端口
?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) #這裏選擇JHipster Registry
? Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle, MSSQL) #根據自己的需求選擇數據庫, 這裏我選擇sql
? Which *production* database would you like to use? MySQL
? Which *development* database would you like to use? MySQL
?Do you want to use the Spring cache abstraction? Yes, with the Hazelcast implementation (distributed cache, for multiple nodes) #選擇 用HAZELCAST實現
? Do you want to use Hibernate 2nd level cache? yes #是否選擇二級緩存 這裏yes
? Would you like to use Maven or Gradle for building the backend? Maven #項目選擇maven構建後端 也可以選擇gradle
? 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? Gatling
? Would you like to install other generators from the JHipster Marketplace? (y/N) n
# 應用程序生成成功後, 執行一下命令來啓動程序:
yarn install #安裝依賴
mvnw #啓動後端
程序啓動成功後, 在註冊中心:http://localhost:8761/ 即可看到運行情況,具體效果圖如下:
3. 創建網關:
大體步驟和創建uaa一致,回答一系列問題後執行相同的命令來啓動後端,這裏直接只展示效果圖,不再贅述:
4. 創建微服務應用:
由於步驟與創建uaa和創建網關的步驟雷同, 所以這裏就只展示後端啓動成功後的效果圖:
在創建微服務時,需要在application-dev.yml 和 application-prod.yml 文件中進行相應的配置 , 不然在啓動後端時會報錯。
到這裏就操作成功了。
5, 測試:
可以在service3中創建實體empinfo查看在網關中是否能夠調用服務。
新人上路,請多指教!!!!!
參考文章:https://my.oschina.net/niepanLs/blog/792493
https://juejin.im/post/5b1c7f605188257d3a6973a0