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

Describe the bug I bumped to the latest version of spring-cloud-gcp (5.1.0) for the various dependencies that use:

<dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>spring-cloud-gcp-pubsub</artifactId>
      <version>${spring-cloud-gcp.version}</version>
    </dependency>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>spring-cloud-gcp-core</artifactId>
      <version>${spring-cloud-gcp.version}</version>
    </dependency>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
      <version>${spring-cloud-gcp.version}</version>
    </dependency>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
      <version>${spring-cloud-gcp.version}</version>
    </dependency>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>spring-cloud-gcp-starter</artifactId>
      <version>${spring-cloud-gcp.version}</version>
    </dependency>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>spring-cloud-gcp-autoconfigure</artifactId>
      <version>${spring-cloud-gcp.version}</version>
    </dependency>

And now I get the error java.lang.ClassNotFoundException: com.google.cloud.sql.ConnectorRegistry when I try to start my application. The stacktrace:

Caused by: java.lang.NoClassDefFoundError: com/google/cloud/sql/ConnectorRegistry
	at com.google.cloud.spring.autoconfigure.sql.CloudSqlEnvironmentPostProcessor.postProcessEnvironment(CloudSqlEnvironmentPostProcessor.java:86)
	at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEnvironmentPreparedEvent(EnvironmentPostProcessorApplicationListener.java:109)
	at org.springframework.boot.env.EnvironmentPostProcessorApplicationListener.onApplicationEvent(EnvironmentPostProcessorApplicationListener.java:94)
	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:369)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:329)

Sample If possible, please provide a test case or sample application that reproduces the problem. This makes it much easier for us to diagnose the problem and to verify that we have fixed it.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (10 by maintainers)

Most upvoted comments

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!

@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.

I will investigate this issue.