Coder Social home page Coder Social logo

java.lang.ClassNotFoundException: com.google.cloud.sql.ConnectorRegistry when using spring-cloud-gcp v.5.1.0 about spring-cloud-gcp HOT 18 CLOSED

amynguyen780 avatar amynguyen780 commented on August 17, 2024
java.lang.ClassNotFoundException: com.google.cloud.sql.ConnectorRegistry when using spring-cloud-gcp v.5.1.0

from spring-cloud-gcp.

Comments (18)

ttosta-google avatar ttosta-google commented on August 17, 2024 1

I will investigate this issue.

from spring-cloud-gcp.

ttosta-google avatar ttosta-google commented on August 17, 2024 1

@amynguyen780 The <dependencyManagement> only controls the version, it does not add the dependency.

My pom.xml file is:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-dependencies</artifactId>
            <version>5.1.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
     </dependency>
</dependencies>

Please try the following:

mvn clean install -U

mvn spring-boot:run

I was not able to reproduce your issue.

The latest changes are used by the spring-cloud-gcp-sql-postgres-sample and it works.

from spring-cloud-gcp.

ttosta-google avatar ttosta-google commented on August 17, 2024 1

One option is to add the following to com.spotify:bom dependency, so the Cloud SQL deps version will be defined by spring-cloud-gcp-dependencies:5.1.0.

<exclusions>
    <exclusion>
        <groupId>com.google.cloud.sql</groupId>
        <artifactId>postgres-socket-factory</artifactId>
    </exclusion>
    <exclusion>
        <groupId>com.google.cloud.sql</groupId>
        <artifactId>jdbc-socket-factory-core</artifactId>
    </exclusion>
</exclusions>

Since this is not a bug, I'll close this ticket. If you encounter any new issues, feel free to report them by opening a new bug ticket. Thanks!

from spring-cloud-gcp.

meltsufin avatar meltsufin commented on August 17, 2024

@ttosta-google FYI

from spring-cloud-gcp.

ttosta-google avatar ttosta-google commented on August 17, 2024

Thanks @amynguyen780 for reporting this issue.

Try adding the BOM to your pom.xml like recommended here:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-dependencies</artifactId>
            <version>5.1.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Please let us know if it fixes this issue.

from spring-cloud-gcp.

amynguyen780 avatar amynguyen780 commented on August 17, 2024

So I added what you suggested and removed all the other dependencies I specified in the issue description since I assumed that this pom would cover all of those but then it apparently didn't and I needed to add back spring-cloud-gcp-pubsub and spring-cloud-gcp-starter-sql-postgresql, and then I get the same error when I start the application about java.lang.NoClassDefFoundError: com/google/cloud/sql/ConnectorRegistry.

from spring-cloud-gcp.

amynguyen780 avatar amynguyen780 commented on August 17, 2024

@ttosta-google any ideas?

from spring-cloud-gcp.

amynguyen780 avatar amynguyen780 commented on August 17, 2024

Got it. Ok so then I tried leaving all of the dependencies I had specified before but removed the pinned version at those individual dependencies and used the dependencyManagement pom import to specify the version, but I'm still getting the same error when trying to run the application. Did com.google.cloud.sql.ConnectorRegistry get moved to a different library in the version bump? I even tried using the latest version (5.1.2), but yeah something about from 5.1.0 on, this import is not being resolved.

from spring-cloud-gcp.

amynguyen780 avatar amynguyen780 commented on August 17, 2024

Ah I see this particular file got changed here. And I ran mvn dependency:tree and saw:

[INFO] +- com.google.cloud:spring-cloud-gcp-starter-sql-postgresql:jar:5.1.0:compile
[INFO] |  +- com.google.cloud.sql:postgres-socket-factory:jar:1.11.1:compile
[INFO] |  |  \- com.google.cloud.sql:jdbc-socket-factory-core:jar:1.11.1:compile

So weirdly, I'm not pulling in the version specified in the pom.xml here but an older one...

from spring-cloud-gcp.

ttosta-google avatar ttosta-google commented on August 17, 2024

The version of com.google.cloud.sql:postgres-socket-factory is defined in the <dependencyManagement> section here. It is possible that another library imported by your project is setting the version to 1.11.1. To confirm this, please run mvn dependency:tree again and check if the library is being used in multiple places.

To force the version 1.16.0 you could add the following to your <dependencyManagement>:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-dependencies</artifactId>
            <version>5.1.0</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
        <dependency>
            <groupId>com.google.cloud.sql</groupId>
            <artifactId>postgres-socket-factory</artifactId>
            <version>1.16.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.cloud.sql</groupId>
            <artifactId>jdbc-socket-factory-core</artifactId>
            <version>1.16.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>

It is only recommended if your project has two libraries defining the version for com.google.cloud.sql:postgres-socket-factory. If your projects only needs spring-cloud-gcp-starter-sql-postgresql, them adding the POM com.google.cloud:spring-cloud-gcp-dependencies should be enough.

from spring-cloud-gcp.

amynguyen780 avatar amynguyen780 commented on August 17, 2024

Looking at the maven dependency tree, I see that I'm only pulling the postgres-socket-factory and jdbc-socket-factory-core dependencies from spring-cloud-gcp-starter-sql-postgresql which is at v5.1.0. I then specified these two dependencies explicitly with v1.16.0 pinned as you have above and it's now using those versions, but now I get another issue:

Caused by: java.lang.NoSuchMethodError: 'java.lang.String com.google.api.services.sqladmin.model.ConnectSettings.getDnsName()'
	at com.google.cloud.sql.core.DefaultConnectionInfoRepository.fetchMetadata(DefaultConnectionInfoRepository.java:217)
	at com.google.cloud.sql.core.DefaultConnectionInfoRepository.lambda$getConnectionInfo$0(DefaultConnectionInfoRepository.java:111)
	at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:131)
	at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:76)
	at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:82)

from spring-cloud-gcp.

ttosta-google avatar ttosta-google commented on August 17, 2024

Please run mvn help:effective-pom -Dverbose and send me the output for postgres-socket-factory and jdbc-socket-factory-core dependencies.

My output is:

<dependency>
    <groupId>com.google.cloud.sql</groupId>  <!-- com.google.cloud:spring-cloud-gcp-dependencies:5.1.0, line 257 -->
    <artifactId>postgres-socket-factory</artifactId>  <!-- com.google.cloud:spring-cloud-gcp-dependencies:5.1.0, line 258 -->
    <version>1.16.0</version>  <!-- com.google.cloud:spring-cloud-gcp-dependencies:5.1.0, line 259 -->
</dependency>

Thanks!

from spring-cloud-gcp.

amynguyen780 avatar amynguyen780 commented on August 17, 2024
<dependency>
        <groupId>com.google.cloud.sql</groupId>  <!-- com.spotify:ads-api-server:0.0.1-SNAPSHOT, line 310 -->
        <artifactId>postgres-socket-factory</artifactId>  <!-- com.spotify:ads-api-server:0.0.1-SNAPSHOT, line 311 -->
        <version>1.16.0</version>  <!-- com.spotify:ads-api-server:0.0.1-SNAPSHOT, line 312 -->
        <scope>compile</scope>
      </dependency>
<dependency>
        <groupId>com.google.cloud.sql</groupId>  <!-- com.spotify:ads-api-server:0.0.1-SNAPSHOT, line 315 -->
        <artifactId>jdbc-socket-factory-core</artifactId>  <!-- com.spotify:ads-api-server:0.0.1-SNAPSHOT, line 316 -->
        <version>1.16.0</version>  <!-- com.spotify:ads-api-server:0.0.1-SNAPSHOT, line 317 -->
        <scope>compile</scope>
      </dependency>

from spring-cloud-gcp.

ttosta-google avatar ttosta-google commented on August 17, 2024

Please remove the Cloud SQL dependencies from your project's <dependencyManagement> first. I would like to see which dependency is setting their version to 1.11.1. Thanks!

from spring-cloud-gcp.

amynguyen780 avatar amynguyen780 commented on August 17, 2024

Ah ok so I removed the pinned 1.16.0 version on these two dependencies and this is what I get:

<dependency>
        <groupId>com.google.cloud.sql</groupId>  <!-- com.spotify:ads-api-server:0.0.1-SNAPSHOT, line 310 -->
        <artifactId>postgres-socket-factory</artifactId>  <!-- com.spotify:ads-api-server:0.0.1-SNAPSHOT, line 311 -->
        <version>1.11.1</version>  <!-- com.spotify:bom:2279, line 1117 -->
        <scope>compile</scope>
      </dependency>
<dependency>
        <groupId>com.google.cloud.sql</groupId>  <!-- com.spotify:ads-api-server:0.0.1-SNAPSHOT, line 314 -->
        <artifactId>jdbc-socket-factory-core</artifactId>  <!-- com.spotify:ads-api-server:0.0.1-SNAPSHOT, line 315 -->
        <version>1.11.1</version>  <!-- com.spotify:bom:2279, line 1102 -->
        <scope>compile</scope>
      </dependency>

If I fully remove these two dependencies, they don't show up in the output.

from spring-cloud-gcp.

ttosta-google avatar ttosta-google commented on August 17, 2024

Now we can see that the Cloud SQL dependencies version is defined by com.spotify:bom:2279. Can you update it to 1.16.0 or 1.17.1 (latest) ?

from spring-cloud-gcp.

amynguyen780 avatar amynguyen780 commented on August 17, 2024

Hm yeah I can look into that but it's strange that just specifying the version in my own project pom.xml wouldn't have been enough since usually that would override the older version being pulled in transitively

from spring-cloud-gcp.

ttosta-google avatar ttosta-google commented on August 17, 2024

@meltsufin can you please close this issue? Thanks!

from spring-cloud-gcp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.