Search code examples
javaspringspring-bootspring-tool-suitegoogle-cloud-spanner

Spring application not booting


I have a spring boot project in Spring tool Suite which connects to a Google Cloud Spanner Database. The credentials for connecting to Spanner are in a JSON file, which I have included as Environment variable in Run configurations.

When I run the application, I am getting the following error and the application terminates.

Failed to instantiate [com.google.cloud.spanner.SpannerOptions]: Factory method 'spannerOptions' threw exception; nested exception is java.lang.NoSuchMethodError: org.json.JSONTokener.<init>(Ljava/io/InputStream;)

I have another project connecting to Spanner and it works absolutely fine. I am using Java 8

Please help me in understanding the cause of this error.


Solution

  • Judging from the error message, it seems that there is a conflict in your dependency tree. One or some of your dependencies are relying on an incompatible version of org.json.JSONTokener, which does not have the constructor that accepts an InputStream as the parameter.

    One thing you can try is to compare the dependencies of your working project and this one. If you are using logback as the logger, you can enable packaging data to print out the jar file that is being used so you can know exactly which library is causing the issue. After knowing what library is causing the issue, you can upgrade the version of the library (note: sometimes it is transitive, so you have to upgrade the library that brings in this problematic package).