I am new to JHipster and I found it is easy to generate a application without sweat. 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:
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. And I did searched on other posts but still not success to run on prod mode.. Any form of help is appreciated. Thanks!
CodePudding user response:
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).
Same thing for all dependencies on external systems like your MySQL database.
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/
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
CodePudding user response:
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. However, for prod
mode, there are 2 ways to start:
First way (when you choose to use JHipster Registry):
- after generating application,
./mvnw package -Pprod verify jib:dockerBuild
or./mvnw -Pprod package verify jib:dockerBuild --offline
- run another console/terminal,
docker-compose -f src/main/docker/app.yml up
, it will run all required services (database, JHipster Registry ,etc) - run
./mvnw -Pprod
, the application should be running successfully.
Second way (not choosing JHipster Registry):
- just run
docker-compose -f src/main/docker/mysql.yml up
instead of./mvnw -Pprod
, it will automatically run the application successfully.
*NOTE: the mysql inside docker-compose -f src/main/docker/mysql.yml up
can be changed depends on your chosen database.
Also, I did not connect to any external database.