jhipster / generator-jhipster

JHipster is a development platform to quickly generate, develop, & deploy modern web applications & microservice architectures.
https://www.jhipster.tech
Apache License 2.0
21.58k stars 4.02k forks source link

JHipster generator can't generate a Microservice project that works by default without cloud environment #27703

Open k888888888888888888 opened 3 weeks ago

k888888888888888888 commented 3 weeks ago
The project is not able to run without using many computers or cloud environment

If you try to start the containerized version of docker:

npm run java:docker docker compose -f src/main/docker/app.yml up -d

[+] Running 15/15 ✔ postgresql 14 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿] 0B/0B Pulled 21.4s ✔ a480a496ba95 Pull complete 5.8s ✔ 894a87c2a602 Pull complete 5.8s ✔ 5c683167ebb4 Pull complete 5.9s ✔ a4a2ff601989 Pull complete 6.0s ✔ f9f18b35445d Pull complete 6.2s ✔ 4341d9f4d10b Pull complete 6.3s ✔ d75b4dfa7494 Pull complete 6.3s ✔ 79531d2c07af Pull complete 6.4s ✔ 38d735e5fe5b Pull complete 16.0s ✔ 021a1a38fd6a Pull complete 19.4s ✔ f79edff05c77 Pull complete 19.5s ✔ 09219b44bd7a Pull complete 19.5s ✔ 9b2fb85f538d Pull complete 19.6s ✔ 1a6cb584f284 Pull complete 19.6s [+] Running 4/5 ✔ Network assembly_default C... 0.1s ✔ Container assembly-keycloak-1 Healthy 22.7s ⠿ Container assembly-postgresql-1 Starting 23.0s ✔ Container assembly-jhipster-registry-1 Started 22.3s ✔ Container mygateway-app-1 C... 0.1s

listen tcp 127.0.0.1:5432: bind: address already in use

It tries to launch 2 instances of PostgreSQL since the gateway includes the definition of docker container for PostgreSQL but for each microservice if uses the same database engine you will have another docker container definition.

So 1 gateway and 4 services with MySQL would result in a conflict for port 3306 since there is no docker network defined and all ports are binded to the same in the host OS.

Motivation for or Use Case

The application will not works in container mode for microservice JDL since gateway + N services will conflict same port for databases of each component.

Reproduce the error
  1. nvm use 20.12.2
  2. jhipster jdl microservice.jdl
  3. cd mygateway
  4. npm run java:docker
  5. docker compose -f src/main/docker/app.yml up -d
  6. Enjoy.

If you try to remove mysql.yml containers and references in all configuration files you will got exception perhaps because is hard-coded somewhere ???

`miguel@HP-EliteBook-650-15-6-inch-G9-Notebook-PC:~/Documents/REPOSITORIES/microservice/retailbox$ ./mvnw [INFO] Scanning for projects... [INFO] [INFO] -----------------------< com.myMicroservice:myAppA >----------------------- [INFO] Building myAppA 0.0.1-SNAPSHOT [INFO] from pom.xml [INFO] --------------------------------[ jar ]--------------------------------- [INFO] [INFO] >>> spring-boot:3.3.4:run (default-cli) > test-compile @ myAppA >>> [INFO] [INFO] --- enforcer:3.5.0:enforce (enforce-versions) @ myAppA --- [INFO] Rule 0: org.apache.maven.enforcer.rules.version.RequireMavenVersion passed [INFO] Rule 1: org.apache.maven.enforcer.rules.version.RequireJavaVersion passed [INFO] [INFO] --- enforcer:3.5.0:enforce (enforce-dependencyConvergence) @ myAppA --- [WARNING] Rule 0: org.apache.maven.enforcer.rules.dependency.DependencyConvergence failed with message: Failed while enforcing releasability.

Dependency convergence error for com.google.guava:guava:jar:14.0.1 paths to dependency are: +-com.myMicroservice:myAppA:jar:0.0.1-SNAPSHOT +-org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar:4.1.3:compile +-com.netflix.eureka:eureka-client:jar:2.0.3:compile +-com.netflix.netflix-commons:netflix-eventbus:jar:0.3.0:runtime +-com.netflix.netflix-commons:netflix-infix:jar:0.3.0:runtime +-com.google.guava:guava:jar:14.0.1:runtime and +-com.myMicroservice:myAppA:jar:0.0.1-SNAPSHOT +-org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar:4.1.3:compile +-com.netflix.eureka:eureka-client:jar:2.0.3:compile +-com.netflix.netflix-commons:netflix-eventbus:jar:0.3.0:runtime +-com.netflix.servo:servo-core:jar:0.5.3:runtime +-com.google.guava:guava:jar:14.0.1:runtime and +-com.myMicroservice:myAppA:jar:0.0.1-SNAPSHOT +-org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar:4.1.3:compile +-com.netflix.eureka:eureka-core:jar:2.0.3:compile +-com.google.guava:guava:jar:33.0.0-jre:runtime

[INFO] [INFO] --- properties:1.2.1:read-project-properties (default) @ myAppA --- [INFO] Loading 26 properties from File: /home/naaaa/Documents/REPOSITORIES/microservice/myAppA/sonar-project.properties [INFO] [INFO] --- jacoco:0.8.12:prepare-agent (pre-unit-tests) @ myAppA --- [INFO] argLine set to -javaagent:/home/naaaa/.m2/repository/org/jacoco/org.jacoco.agent/0.8.12/org.jacoco.agent-0.8.12-runtime.jar=destfile=/home/naaaa/Documents/REPOSITORIES/microservice/myAppA/target/jacoco.exec -Djava.security.egd=file:/dev/./urandom -Xmx1G [INFO] [INFO] --- spotless:2.43.0:apply (spotless) @ myAppA --- [INFO] Spotless.Java is keeping 74 files clean - 0 were changed to be clean, 0 were already clean, 74 were skipped because caching determined they were already clean [INFO] [INFO] --- spring-boot:3.3.4:build-info (build-info) @ myAppA --- [INFO] [INFO] --- resources:3.3.1:resources (default-resources) @ myAppA --- [INFO] Copying 6 resources from src/main/resources to target/classes [INFO] Copying 11 resources from src/main/resources to target/classes [INFO] [INFO] --- compiler:3.13.0:compile (default-compile) @ myAppA --- [INFO] Nothing to compile - all classes are up to date. [INFO] [INFO] --- resources:3.3.1:testResources (default-testResources) @ myAppA --- [INFO] Copying 7 resources from src/test/resources to target/test-classes [INFO] [INFO] --- compiler:3.13.0:testCompile (default-testCompile) @ myAppA --- [INFO] Nothing to compile - all classes are up to date. [INFO] [INFO] <<< spring-boot:3.3.4:run (default-cli) < test-compile @ myAppA <<< [INFO] [INFO] [INFO] --- spring-boot:3.3.4:run (default-cli) @ myAppA --- [INFO] Attaching agents: [] 2024-10-28T09:36:01.174+01:00 ERROR 1608050 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

java.lang.IllegalStateException: No Docker Compose file found in directory '/home/naaaa/Documents/REPOSITORIES/microservice/myAppA/.' at org.springframework.util.Assert.state(Assert.java:97) at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.getComposeFile(DockerComposeLifecycleManager.java:149) at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.start(DockerComposeLifecycleManager.java:109) at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:53) at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:35) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:98) at org.springframework.boot.SpringApplicationRunListeners.lambda$contextLoaded$4(SpringApplicationRunListeners.java:72) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:72) at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:433) at org.springframework.boot.SpringApplication.run(SpringApplication.java:334) at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149) at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:195) at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114) at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:77) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81) at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:370) at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) at com.myMicroservice.myAppA.main(myAppA.java:70) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50)

2024-10-28T09:36:01.177+01:00 ERROR 1608050 --- [ restartedMain] o.s.boot.SpringApplication : Application run failed

java.lang.IllegalStateException: No Docker Compose file found in directory '/home/naaaa/Documents/REPOSITORIES/microservice/myAppA/.' at org.springframework.util.Assert.state(Assert.java:97) at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.getComposeFile(DockerComposeLifecycleManager.java:149) at org.springframework.boot.docker.compose.lifecycle.DockerComposeLifecycleManager.start(DockerComposeLifecycleManager.java:109) at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:53) at org.springframework.boot.docker.compose.lifecycle.DockerComposeListener.onApplicationEvent(DockerComposeListener.java:35) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) at org.springframework.boot.context.event.EventPublishingRunListener.contextLoaded(EventPublishingRunListener.java:98) at org.springframework.boot.SpringApplicationRunListeners.lambda$contextLoaded$4(SpringApplicationRunListeners.java:72) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) at org.springframework.boot.SpringApplicationRunListeners.contextLoaded(SpringApplicationRunListeners.java:72) at org.springframework.boot.SpringApplication.prepareContext(SpringApplication.java:433) at org.springframework.boot.SpringApplication.run(SpringApplication.java:334) at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:149) at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:195) at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:114) at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:77) at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:185) at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:178) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:156) at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:138) at org.springframework.boot.context.event.EventPublishingRunListener.multicastInitialEvent(EventPublishingRunListener.java:136) at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:81) at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:64) at java.base/java.lang.Iterable.forEach(Iterable.java:75) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:118) at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:112) at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:63) at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:370) at org.springframework.boot.SpringApplication.run(SpringApplication.java:330) at com.myMicroservice.myAppA.main(myAppA.java:70) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:568) at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:50)

[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 2.754 s [INFO] Finished at: 2024-10-28T09:36:01+01:00 [INFO] ------------------------------------------------------------------------ `

Related issues

https://github.com/jhipster/generator-jhipster/issues/27685

Suggest a Fix

Make appropriate docker network and make sure bind different ports to the host OS example: mysql 1 : 3307 , mysql 2: 3308 , etc ...

Also I suggest do not close issues that are reported and not solved.

JHipster Version(s)

v8.7.1

JHipster configuration

Welcome to JHipster v8.7.1

Welcome to the JHipster Information Sub-Generator

/home/********/microservice
└── (empty)
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "generator-jhipster": {
    "baseName": "workspaces",
    "directoryPath": "./",
    "jhipsterVersion": "8.7.1"
  }
}
Environment and Tools

openjdk version "1.8.0_302" OpenJDK Runtime Environment (build 1.8.0_302-b08) OpenJDK 64-Bit Server VM (build 25.302-b08, mixed mode)

git version 2.34.1

node: v20.12.2 npm: 10.5.0

Docker version 24.0.2, build cb74dfc

JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions

As alternative you can add a JDL wrapped in below structure

JDL definitions
     application {
  config {
    baseName mygateway
    applicationType gateway
    packageName com.assembly
    authenticationType oauth2
    prodDatabaseType postgresql
    clientFramework angularX
    serviceDiscoveryType eureka
    buildTool maven
    cacheProvider no
    skipClient false
    serverPort 8080
  }
  entities *
}

application {
  config {
    baseName myappa
    applicationType microservice
    packageName com.prestage
    authenticationType jwt
    serviceDiscoveryType eureka
    prodDatabaseType postgresql
    buildTool maven
    cacheProvider no
    serverPort 8081
  }
  entities Unit, SetupProcess
}

application {
  config {
    baseName myappb
    applicationType microservice
    packageName com.prestage
    authenticationType jwt
    serviceDiscoveryType eureka
    prodDatabaseType postgresql
    buildTool maven
    cacheProvider no
    serverPort 8082
  }
  entities SmartLock
}

entity MyEntityB {
    name String
    dateCreation Date
    result Boolean
}

enum MyEnum{
    ONE,
    TWO
}

entity MyEntityA {
    name String
    location String
    myenumValue MyEnum
}

entity MyEntityC {
    id UUID
    model String
    finished Boolean
}

relationship OneToOne {
  MyEntityA to MyEntityB
}

service all with serviceImpl 

paginate MyEntityA, MyEntityC with pagination

microservice MyEntityA, MyEntityB with myappa

microservice MyEntityC with myappb

  
Browsers and Operating System

Not relevant.

atomfrede commented 3 weeks ago

Just to make sure, do you want to use it without any usage of docker or do you want the default docker config to be working with multiple services using the same database? As in your other ticket it sounded like docker has been the problem.

k888888888888888888 commented 3 weeks ago

Just to make sure, do you want to use it without any usage of docker or do you want the default docker config to be working with multiple services using the same database? As in your other ticket it sounded like docker has been the problem.

In previous versions of Jhipster you decide if use docker or not, you can launch: database, registry, control center, anything you need.

Anyway if use docker with microservice will be a conflict with the port if many services including gateway use same database engine: listen tcp 127.0.0.1:5432: bind: address already in use.

I'm missing the use case of JHipster ? how do you do if have multiple microservices in your local environment ? Regardless if you run everything in containers it shouldn't have port conflicts. And setup to use local database should be easy, currently is very coupled to docker containers.

atomfrede commented 3 weeks ago

You can still do that. The default docker configs have always used fixed ports (the default port of the database) so it can be switched to a non containerized database without any changes to the application config. With the new compose support by spring boot we can enhance it and remove the fixed port bindings and let boot auto discover the used port. But in case you want to use a local database you would have to configure the services, thats why we have a fixed port binding for now (which is not perfect, but considered using different dbs for each service it worked pretty well).