简体   繁体   English

JHipster:在 localhost 上运行生产配置文件

[英]JHipster: run production profile on localhost

I am new to JHipster and I found it is easy to generate a application without sweat.我是 JHipster 的新手,我发现生成一个应用程序很容易而不费吹灰之力。 I tried to generate a simple monolithic application and ran on dev mode and it worked like charm.我尝试生成一个简单的单片应用程序并在开发模式下运行,它的工作就像魅力一样。 However, when I want to run production mode using "./mvnw -Pprod" it shows error:但是,当我想使用“./mvnw -Pprod”运行生产模式时,它会显示错误:

 2022-06-30 14:52:30.639 ERROR 9088 --- [           main] o.s.boot.SpringApplication               : Application run failed
java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:148)
    at org.springframework.cloud.bootstrap.config.PropertySourceLocator.locateCollection(PropertySourceLocator.java:51)
    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locateCollection(ConfigServicePropertySourceLocator.java:160)
    at org.springframework.cloud.bootstrap.config.PropertySourceBootstrapConfiguration.initialize(PropertySourceBootstrapConfiguration.java:95)
    at org.springframework.boot.SpringApplication.applyInitializers(SpringApplication.java:613)
    at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:381)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:302)
    at com.sample.JtestingApp.main(JtestingApp.java:69)
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://localhost:8761/config/Jtesting/prod/main": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:785)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:711)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:602)
    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.getRemoteEnvironment(ConfigServicePropertySourceLocator.java:255)
    at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:109)
    ... 7 common frames omitted
Caused by: java.net.ConnectException: Connection refused (Connection refused)
    at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:412)
    at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:255)
    at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:237)
    at java.base/java.net.Socket.connect(Socket.java:609)
    at java.base/sun.net.NetworkClient.doConnect(NetworkClient.java:177)
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:474)
    at java.base/sun.net.www.http.HttpClient.openServer(HttpClient.java:569)
    at java.base/sun.net.www.http.HttpClient.<init>(HttpClient.java:242)
    at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:341)
    at java.base/sun.net.www.http.HttpClient.New(HttpClient.java:362)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1253)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1187)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1081)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:1015)
    at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76)
    at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
    at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:66)
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:776)
    ... 11 common frames omitted

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  03:53 min
[INFO] Finished at: 2022-06-30T14:52:30+08:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.6.6:run (default-cli) on project jtesting: Application finished with exit code: 1 -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

These are my choices when I generating application in case you need it:这些是我在生成应用程序时的选择,以备不时之需: 在此处输入图像描述

I didn't edit or change any coding so far because I want to see the difference of dev and prod.到目前为止,我没有编辑或更改任何编码,因为我想看看 dev 和 prod 的区别。 And I did searched on other posts but still not success to run on prod mode.. Any form of help is appreciated.而且我确实在其他帖子上进行了搜索,但在 prod 模式下运行仍然没有成功。任何形式的帮助都值得赞赏。 Thanks谢谢

You chose to use JHipster registry to serve configuration and to scale up, so when you run your app in production mode you must start jhipster-registry application and also make sure you have copied the application properties to the registry repository (either git or a directory).您选择使用 JHipster 注册表来提供配置和扩展,因此当您在生产模式下运行您的应用程序时,您必须启动 jhipster-registry 应用程序并确保您已将应用程序属性复制到注册表存储库(git 或目录)。

Same thing for all dependencies on external systems like your MySQL database.对于像 MySQL 数据库这样的外部系统的所有依赖项也是如此。

Easiest way to start them in local development environment is to use docker-compose, see official doc for details: https://www.jhipster.tech/docker-compose/在本地开发环境中启动它们的最简单方法是使用 docker-compose,详细信息请参见官方文档: https://www.jhipster.tech/docker-compose/

If you want only to build your app (not running it) using prod profile, you can do it without external systems, you just need to specify the package goal: mvnw -Pprod package如果您只想使用prod配置文件构建您的应用程序(不运行它),您可以在没有外部系统的情况下执行此操作,您只需指定package目标: mvnw -Pprod package

Ok, so I just post here for other begineers or my future reference (only run for localhost, not cloud).好的,所以我只是在这里发布以供其他初学者或我将来参考(仅针对本地主机运行,而不是云)。 Running dev mode is easy, just use mvnw after generating application.运行dev模式很简单,生成应用程序后使用mvnw However, for prod mode, there are 2 ways to start:但是,对于prod模式,有两种启动方式:

First way (when you choose to use JHipster Registry):第一种方式(当您选择使用 JHipster Registry 时):

  1. after generating application, ./mvnw package -Pprod verify jib:dockerBuild or ./mvnw -Pprod package verify jib:dockerBuild --offline生成应用程序后, ./mvnw package -Pprod verify jib:dockerBuild or ./mvnw -Pprod package verify jib:dockerBuild --offline
  2. run another console/terminal, docker-compose -f src/main/docker/app.yml up , it will run all required services (database, JHipster Registry,etc)运行另一个控制台/终端docker-compose -f src/main/docker/app.yml up ,它将运行所有必需的服务(数据库、JHipster Registry 等)
  3. run ./mvnw -Pprod , the application should be running successfully.运行./mvnw -Pprod ,应用程序应该可以成功运行。

Second way (not choosing JHipster Registry):第二种方式(不选择 JHipster Registry):

  1. just run docker-compose -f src/main/docker/mysql.yml up instead of ./mvnw -Pprod , it will automatically run the application successfully.只需运行docker-compose -f src/main/docker/mysql.yml up而不是./mvnw -Pprod ,它将自动成功运行应用程序。

*NOTE: the mysql inside docker-compose -f src/main/docker/mysql.yml up can be changed depends on your chosen database. *注意: docker-compose docker-compose -f src/main/docker/mysql.yml up中的 mysql 可以根据您选择的数据库进行更改。

Also, I did not connect to any external database.另外,我没有连接到任何外部数据库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM