JHipster本地运行prod生产模式启动报8761连接被拒绝错误
JHipster单体应用prod模式启动连接被拒绝问题
问题现象
我是JHipster初学者,该框架可快速生成应用,我生成了一个简单单体应用,dev开发模式下运行完全正常,但使用./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.
报错根因为请求http://localhost:8761/config/Jtesting/prod/main时出现连接被拒绝异常,最终Maven构建失败。应用生成时的选型配置可参考附图,目前未修改任何代码,仅想对比dev与prod模式的运行差异,查阅资料后仍无法成功启动prod模式。
故障原因
生成应用时勾选了Spring Cloud相关组件,JHipster的prod模式默认开启Spring Cloud Config客户端的强制拉取配置逻辑:启动时必须从localhost:8761(JHipster Registry默认端口,同时承担注册中心、配置中心能力)拉取远程配置,且fail-fast参数默认为true,拉取失败直接终止启动。而dev模式默认关闭了强制拉取逻辑,因此可以正常启动。
解决方法
根据使用场景二选一即可:
- 仅本地测试prod模式,不需要使用注册中心/配置中心
修改src/main/resources/config/application-prod.yml文件,找到Spring Cloud Config配置段,直接禁用配置中心能力即可,参考配置:
保存后重新执行spring: cloud: config: enabled: false fail-fast: false discovery: enabled: false./mvnw -Pprod即可正常启动,无需额外依赖其他服务。 - 需要模拟完整生产架构运行
先单独启动JHipster Registry服务,等待其完全启动、8761端口正常监听后,再执行./mvnw -Pprod启动单体应用,应用会自动从Registry拉取配置完成启动。
内容的提问来源于stack exchange,提问作者ZonG
相关产品推荐
相关产品推荐

