我是 JHipster 的新手,我發現生成一個應用程式很容易而不費吹灰之力。我嘗試生成一個簡單的單片應用程式并在開發模式下運行,它的作業就像魅力一樣。但是,當我想使用“./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
這些是我在生成應用程式時的選擇,以備不時之需:

到目前為止,我沒有編輯或更改任何編碼,因為我想看看 dev 和 prod 的區別。而且我確實在其他帖子上進行了搜索,但在 prod 模式下運行仍然沒有成功。任何形式的幫助都值得贊賞。謝謝!
uj5u.com熱心網友回復:
您選擇使用 JHipster 注冊表來提供配置和擴展,因此當您在生產模式下運行您的應用程式時,您必須啟動 jhipster-registry 應用程式并確保您已將應用程式屬性復制到注冊表存盤庫(git 或目錄)。
對外部系統(如 MySQL 資料庫)的所有依賴項也是如此。
在本地開發環境中啟動它們最簡單的方法是使用 docker-compose,詳細資訊請參見官方檔案:https ://www.jhipster.tech/docker-compose/
如果您只想使用prod組態檔構建您的應用程式(而不是運行它),您可以在沒有外部系統的情況下完成,您只需要指定package目標:mvnw -Pprod package
uj5u.com熱心網友回復:
好的,所以我只是在這里發布以供其他初學者或我將來參考(僅針對本地主機運行,而不是云)。運行dev模式很簡單,mvnw生成應用程式后即可使用。但是,對于prod模式,有兩種啟動方式:
第一種方式(當您選擇使用 JHipster Registry 時):
- 生成應用程式后,
./mvnw package -Pprod verify jib:dockerBuild或./mvnw -Pprod package verify jib:dockerBuild --offline - 運行另一個控制臺/終端,
docker-compose -f src/main/docker/app.yml up它將運行所有必需的服務(資料庫、JHipster Registry 等) - run
./mvnw -Pprod,應用程式應該可以成功運行。
第二種方式(不選擇 JHipster Registry):
- 只需運行
docker-compose -f src/main/docker/mysql.yml up而不是./mvnw -Pprod,它將自動成功運行應用程式。
*注意:里面的mysqldocker-compose -f src/main/docker/mysql.yml up可以根據您選擇的資料庫進行更改。
另外,我沒有連接到任何外部資料庫。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/498136.html
下一篇:無法從類加載器層次結構中掃描[jar:file:/app.jar!/BOOT-INF/lib/spring-webmvc-5.2.5.RELEASE.jar!/]
