GoogleCloudPlatform / pgadapter

PostgreSQL wire-protocol proxy for Cloud Spanner
https://cloud.google.com/spanner/docs/postgresql-interface#postgresql-client-support
Apache License 2.0
59 stars 21 forks source link

Exception using PGAdapter with Spring JPA #1102

Closed HendPro12 closed 1 year ago

HendPro12 commented 1 year ago

I'm following along with this documentation https://cloud.google.com/spanner/docs/use-spring-data-jpa-postgresql. My PGAdapter class matches the one in your example. When my service starts up I see the following logs.

Oct 05, 2023 10:40:40 AM com.google.cloud.spanner.pgadapter.ProxyServer startServer
INFO: Server started on port 9432

However, after these additional log entries:

o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
o.apache.catalina.core.StandardService   : Starting service [Tomcat]
org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.78]
o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2898 ms
o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
org.hibernate.Version                    : HHH000412: Hibernate ORM core version 5.6.15.Final
o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.1.2.Final}
com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
c.g.cloud.spanner.pgadapter.ProxyServer  : Socket ServerSocket[addr=localhost/127.0.0.1,localport=9432] stopped

The following exception is thrown:

Exception in thread "spanner-postgres-adapter-proxy-listener" java.lang.NoSuchMethodError: 'com.google.common.cache.CacheBuilder com.google.common.cache.CacheBuilder.expireAfterWrite(java.time.Duration)'
    at com.google.cloud.spanner.pgadapter.ConnectionHandler.<init>(ConnectionHandler.java:112)
    at com.google.cloud.spanner.pgadapter.ConnectionHandler.<init>(ConnectionHandler.java:143)
    at com.google.cloud.spanner.pgadapter.ProxyServer.createConnectionHandler(ProxyServer.java:315)
    at com.google.cloud.spanner.pgadapter.ProxyServer.runServer(ProxyServer.java:287)
    at com.google.cloud.spanner.pgadapter.ProxyServer.runTcpServer(ProxyServer.java:247)
    at com.google.cloud.spanner.pgadapter.ProxyServer.lambda$doStart$2(ProxyServer.java:143)
    at com.google.cloud.spanner.pgadapter.ProxyServer$1.run(ProxyServer.java:159)

Here is the entry point of my Spring Boot application.

public class MyApplication {

    private static final PGAdapter pgAdapter = new PGAdapter();

    public static void main(String[] args) {
        SpringApplication.run(MyApplication.class, args);
    }

    @PreDestroy
    public void onExit() {
        // Stop PGAdapter when the application is shut down.
        pgAdapter.stopPGAdapter();
    }
}

Im using postgres driver 42.6.0 and I've tried both 0.23.1 and 0.24.0 of google-cloud-spanner-pgadapter.

olavloite commented 1 year ago

@HendPro12 Thanks for reporting this. Would you mind sharing your pom.xml or other build file? My expectation is that it is caused by a dependency conflict in the build, most likely related to two different versions of Guava being added by different build dependencies.

HendPro12 commented 1 year ago

@olavloite Thanks. My project was built using two dependencies required by my employer that are using springboot 2.7.14 including spring-boot-starter-data-jpa. I think that is where the issue is stemming from.

olavloite commented 1 year ago

@olavloite Thanks. My project was built using two dependencies required by my employer that are using springboot 2.7.14 including spring-boot-starter-data-jpa. I think that is where the issue is stemming from.

Thanks for getting back to us. Is there anything you would like us to do? Or can we close this issue for now?

HendPro12 commented 1 year ago

@olavloite No, I think this is something I need to sort out from my end. Thanks for the guidance.