Home > Software engineering >  Error while calling spring boot api which is deployed in google App Engine through Cloud build
Error while calling spring boot api which is deployed in google App Engine through Cloud build

Time:12-17

I am getting below response when calling any api of my spring boot application (Application is deployed in App Engine through Cloud Build)

<html>
    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        <title>500 Server Error</title>
    </head>
    <body text=#000000 bgcolor=#ffffff>
        <h1>Error: Server Error</h1>
        <h2>The server encountered an error and could not complete your request.
            <p>Please try again in 30 seconds.
            </h2>
            <h2></h2>
        </body>
    </html>

when I check the logs it said APPLICATION FAILED TO START with below errors

o.s.b.web.embedded.tomcat.TomcatStarter : Error starting Tomcat context. Exception: org.springframework.beans.factory.UnsatisfiedDependencyException. Message: Error creating bean with name 'jwtRequestFilter': Unsatisfied dependency expressed through field 'userDetailsService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'userDetailsService': Unsatisfied dependency expressed through field 'userRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userRepository' defined in com.insta.invoice.repository.UserRepository defined in @EnableJpaRepositories declared on InstaInvoiceApplication: Cannot create inner bean '(inner bean)#cd1d761' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#cd1d761': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: 'void com.google.common.base.Throwables.throwIfUnchecked(java

2022-12-13 19:52:47.938 ERROR 11 --- [pool-1-thread-2] c.g.cloud.sql.core.CloudSqlInstance : Got more than one input failure. Logging failures after the first

java.lang.NoSuchMethodError: 'long com.google.common.io.ByteStreams.exhaust(java.io.InputStream)' at com.google.api.client.http.ConsumingInputStream.close(ConsumingInputStream.java:40) ~[google-http-client-1.41.5.jar!/:1.41.5] at java.base/java.util.zip.InflaterInputStream.close(InflaterInputStream.java:231) ~[na:na] at java.base/java.util.zip.GZIPInputStream.close(GZIPInputStream.java:136) ~[na:na] at java.base/java.io.BufferedInputStream.close(BufferedInputStream.java:481) ~[na:na] at java.base/sun.nio.cs.StreamDecoder.implClose(StreamDecoder.java:366) ~[na:na] at java.base/sun.nio.cs.StreamDecoder.close(StreamDecoder.java:204) ~[na:na] at java.base/java.io.InputStreamReader.close(InputStreamReader.java:192) ~[na:na] at com.google.gson.stream.JsonReader.close(JsonReader.java:1229) ~[gson-2.9.1.jar!/:na] at com.google.api.client.json.gson.GsonParser.close(GsonParser.java:51) ~[google-http-client-gson-1.41.5.jar!/:na] at com.google.api.client.json.JsonParser.parse(JsonParser.java:363) ~[google-http-client-1.41.5.jar!/:1.41.5] at com.google.api.client.json.JsonParser.parse(JsonParser.java:335) ~[google-http-client-1.41.5.jar!/:1.41.5] at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:79) ~[google-http-client-1.41.5.jar!/:1.41.5] at com.google.api.client.json.JsonObjectParser.parseAndClose(JsonObjectParser.java:73) ~[google-http-client-1.41.5.jar!/:1.41.5] at com.google.api.client.http.HttpResponse.parseAs(HttpResponse.java:461) ~[google-http-client-1.41.5.jar!/:1.41.5] at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:565) ~[google-api-client-1.32.1.jar!/:1.32.1] at com.google.cloud.sql.core.CloudSqlInstance.fetchMetadata(CloudSqlInstance.java:462) ~[jdbc-socket-factory-core-1.5.0.jar!/:na] at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:108) ~[guava-19.0.jar!/:na] at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:41) ~[guava-19.0.jar!/:na] at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:77) ~[guava-19.0.jar!/:na] at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[na:na] at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na] at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na] at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na] at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

below is cloudbuild.yaml file

steps:
  - name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
    entrypoint: 'bash'
    args: ['-c', 'gcloud config set app/cloud_build_timeout 1600 && gcloud app deploy']
timeout: '1600s'

options:
  logging: CLOUD_LOGGING_ONLY

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.3</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.insta</groupId>
    <artifactId>filing</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>filing</name>
    <description>Invoice project </description>
<!--    <properties>
        <java.version>1.8</java.version>
    </properties>-->

    <!-- The Spring Cloud GCP BOM will manage spring-cloud-gcp version numbers for you. -->
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>com.google.cloud</groupId>
                <artifactId>spring-cloud-gcp-dependencies</artifactId>
                <version>3.2.1</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>com.google.api-client</groupId>
            <artifactId>google-api-client</artifactId>
            <version>1.32.1</version>
        </dependency>
<!--        <dependency>
            <groupId>org.postgresql</groupId>
            <artifactId>postgresql</artifactId>
            <scope>runtime</scope>
        </dependency>-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-gcp-starter-sql-postgresql</artifactId>
            <version>1.2.4.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.google.cloud.sql</groupId>
            <artifactId>postgres-socket-factory</artifactId>
            <version>1.1.0</version>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-websocket</artifactId>
        </dependency>
        <!-- Spring Security -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <!-- Google Guava -->
        <dependency>
            <groupId>com.google.guava</groupId>
            <artifactId>guava</artifactId>
            <version>19.0</version>
        </dependency>
    <!--    <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-messaging</artifactId>
        </dependency>-->
        <!-- https://mvnrepository.com/artifact/com.twilio.sdk/twilio -->
        <dependency>
            <groupId>com.twilio.sdk</groupId>
            <artifactId>twilio</artifactId>
            <version>8.36.0</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>2.2.0</version>
                <configuration>
                    <version>1</version>
                    <projectId>GCLOUD_CONFIG</projectId>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.6.2</version>
            </plugin>
                        <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <mainClass>com.insta.invoice.InstaInvoiceApplication</mainClass>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

application.properties file

spring.cloud.gcp.sql.instance-connection-name= connection-name
spring.cloud.gcp.sql.database-name=dbName
spring.datasource.username=user
spring.datasource.password=password

# Configure connection pooling if needed
spring.datasource.hikari.maximum-pool-size=10

spring.datasource.driver-class-name =org.postgresql.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL95Dialect
spring.jpa.hibernate.ddl-auto=create

I am trying to get response from my api but Application is failed to start

CodePudding user response:

App is working fine credentials were not created for Cloud SQL Admin API. I have created the credentials and working fine.

  • Related