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.54k stars 4.02k forks source link

Switch to mongodb 4.4.x + #18198

Closed DanielFran closed 1 year ago

DanielFran commented 2 years ago
Overview of the feature request

Mongock now supports reactive driver: https://docs.mongock.io/v5/driver/mongodb-reactive/index.html Thanks @dieppa

We can now remove the workaround created by @mishima with the update to spring-boot 2.6.x (use driver 4.2.3 instead of 4.4.x):

Motivation for or Use Case
Related issues or PR
mraible commented 2 years ago

I tried adjusting jhipster-bom/jhipster-dependencies/pom.xml to remove the exclusions. Before:


<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
    <version>${spring-boot.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.mongodb</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
    <version>${spring-boot.version}</version>
    <exclusions>
        <exclusion>
            <groupId>org.mongodb</groupId>
            <artifactId>*</artifactId>
        </exclusion>
    </exclusions>
</dependency>

After:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
    <version>${spring-boot.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb-reactive</artifactId>
    <version>${spring-boot.version}</version>
</dependency>

Then, I generated an app using the following .yo-rc.json:

{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "sampleWebfluxMongodb",
    "blueprints": [],
    "buildTool": "maven",
    "cacheProvider": "no",
    "clientFramework": "angular",
    "clientPackageManager": "npm",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "creationTimestamp": 1596513172471,
    "databaseType": "mongodb",
    "devDatabaseType": "mongodb",
    "devServerPort": 4200,
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": false,
    "enableTranslation": true,
    "entities": [],
    "entitySuffix": "",
    "jhiPrefix": "jhi",
    "jhipsterVersion": "7.9.3",
    "languages": ["en", "fr"],
    "nativeLanguage": "en",
    "otherModules": [],
    "packageFolder": "tech/jhipster/sample",
    "packageName": "tech.jhipster.sample",
    "pages": [],
    "prodDatabaseType": "mongodb",
    "reactive": true,
    "searchEngine": false,
    "serverPort": "8080",
    "serviceDiscoveryType": false,
    "skipCheckLengthOfIdentifier": false,
    "skipClient": false,
    "skipFakeData": false,
    "skipUserManagement": false,
    "testFrameworks": ["gatling", "cypress"],
    "websocket": false,
    "withAdminUi": true
  }
}

I removed the following from the generated pom.xml:

<!-- Mongock doesn't support reactive yet, so this dependency is necessary. -->
<!-- See https://github.com/jhipster/generator-jhipster/pull/12536#issuecomment-696683592 for more information. -->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

<!-- Mongo db driver was excluded from starter, adding manually. -->
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver-reactivestreams</artifactId>
</dependency>
<!-- Mongo db driver was excluded from starter, adding manually. -->
<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongodb-driver-sync</artifactId>
</dependency>

And added:

<dependency>
    <groupId>io.mongock</groupId>
    <artifactId>mongodb-reactive-driver</artifactId>
</dependency>

Then, I start the app with mvn and it fails to start:

2022-10-20T12:56:10.442-07:00  WARN 63429 --- [  restartedMain] onfigReactiveWebServerApplicationContext : 
Exception encountered during context initialization - cancelling refresh attempt: 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'getBuilder' defined in 
class path resource [io/mongock/runner/springboot/config/MongockContext.class]: Unsatisfied dependency expressed 
through method 'getBuilder' parameter 0: No qualifying bean of type 'io.mongock.driver.api.driver.ConnectionDriver' 
available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} 

2022-10-20T12:56:12.548-07:00 ERROR 63429 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : 
__***************************_APPLICATION FAILED TO START_***************************
__Description:__Parameter 0 of method getBuilder in io.mongock.runner.springboot.config.MongockContext 
required a bean of type 'io.mongock.driver.api.driver.ConnectionDriver' that could not be found.
___Action:__Consider defining a bean of type 'io.mongock.driver.api.driver.ConnectionDriver' in your configuration._ 
dieppa commented 2 years ago

Hi @mraible, @osantana85 was able to reproduce it and we are looking at it

mraible commented 2 years ago

Thank you @dieppa!

atomfrede commented 2 years ago

~Tracking it at jh lite too https://github.com/jhipster/jhipster-lite/issues/4067~ This is about SB 3 not in 2.x but looks similar/related.

mraible commented 2 years ago

@dieppa Do you have an update or issue we can track?

dieppa commented 2 years ago

@mraible https://github.com/mongock/mongock/issues/583. I expect to have a a release by tonight or tomorrow. Thanks!

dieppa commented 1 year ago

@mraible , as you have probably already seen in this Jhipster issue, we have released the mongock runner for springboot 3 and driver for springdata v4.

However I am looking again this ticket and I am wondering if what you need here is an upgrade in the reactive driver. Which, having build the foundation for the jdk7 modules mentioned above(springboot 3 runner and springdata 4 driver), it should be pretty straight forward.

Let me know if you need anything! 😃

atomfrede commented 1 year ago

I will have a look, I also think this is not related to springdata 4 and boot 3 as this is about boot 2. But the error looks the same.

mraible commented 1 year ago

I tried the steps to upgrade to Mongock 5.1.7, followed by these steps from above. I still get an error on startup:

2022-10-27T08:46:28.479+01:00  WARN 2694 --- [  restartedMain] onfigReactiveWebServerApplicationContext : Exception encountered during context 
initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name
'getBuilder' defined in class path resource [io/mongock/runner/springboot/config/MongockContext.class]: Unsatisfied dependency expressed through method 
'getBuilder' parameter 0: Error creating bean with name 'connectionDriver' defined in class path resource 
[io/mongock/driver/mongodb/springdata/v4/config/SpringDataMongoV4Context.class]: Unsatisfied dependency expressed through method 'connectionDriver' 
parameter 0: No qualifying bean of type 'org.springframework.data.mongodb.core.MongoTemplate' available: expected at least 1 bean which qualifies as 
autowire candidate. Dependency annotations: {}

2022-10-27T08:46:30.552+01:00 ERROR 2694 --- [  restartedMain] o.s.b.d.LoggingFailureAnalysisReporter   : __***************************_APPLICATION 
FAILED TO START_***************************__Description:__Parameter 0 of method connectionDriver in 
io.mongock.driver.mongodb.springdata.v4.config.SpringDataMongoV4ContextBase required a bean of type 
'org.springframework.data.mongodb.core.MongoTemplate' that could not be found.___Action:__Consider defining a bean of type 
'org.springframework.data.mongodb.core.MongoTemplate' in your configuration._

If I add the following back in, it starts!

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>

Commits:

atomfrede commented 1 year ago

The mongock driver has the dependency for spring set to provided so I think thats correct. Do I get it correct, this is indeed about boot 3 and not 2?

mraible commented 1 year ago

Yes, this is for Spring Boot 3.

atomfrede commented 1 year ago

Makes sense we don't do such an update for jh 7.x right now. Awesome, so everything looks good here?

mraible commented 1 year ago

@atomfrede I think so. We'll see what CI says.

dieppa commented 1 year ago

I am keeping an eye here to see how it progresses and in what I can help with 👀

mraible commented 1 year ago

Increasing bug bounty since this wasn't easy to solve.

atomfrede commented 1 year ago

@mraible Can we close this from your point of view?

mraible commented 1 year ago

Yes.

atomfrede commented 1 year ago

Bounty claimed https://opencollective.com/generator-jhipster/expenses/106907

pascalgrimaud commented 1 year ago

@atomfrede : approved