Search code examples
javaspring-bootgoogle-app-enginegoogle-cloud-platformgoogle-cloud-sql

Can't get Spring Boot application to work on Google Cloud Platform Flexible Environment


I'm having trouble deploying my Spring Boot application on the Google Cloud Platform Flexible environment.

I run the following command to deploy: mvn clean compile package -DskipTests appengine:deploy -P cloud-gcp

The cloud-gcp profile in my pom.xml has the following:

<profiles>
        <profile>
            <id>cloud-gcp</id>
            <build>
                <plugins>
                    <plugin>
                        <groupId>com.google.cloud.tools</groupId>
                        <artifactId>appengine-maven-plugin</artifactId>
                        <version>1.3.2</version>
                        <configuration>
                            <version>beta3</version>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>

This is my app.yaml file located at src/main/appengine/app.yaml:

runtime: java
env: flex
runtime_config:
  jdk: openjdk8
env_variables:
  SPRING_PROFILES_ACTIVE: "gcp"

handlers:
- url: /.*
  script: this field is required, but ignored
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 4
  disk_size_gb: 10

Here is my application-gcp.properties:

server.address=0.0.0.0
server.port=8080

# Datasource
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
spring.datasource.username=xxx
spring.datasource.password=xxx
spring.datasource.url=jdbc:postgresql://google/xxx?cloudSqlInstance=xxx:europe-west4:xxx&autoReconnect=true&user=xxx&password=xxx&socketFactory=com.google.cloud.sql.postgres.SocketFactory&useSSL=false


server.error.whitelabel.enabled=false

# Optimize start of application
spring.jmx.enabled=false

# Gcp configuration
spring.cloud.gcp.sql.enabled=false
spring.cloud.gcp.sql.database-name=xxx
spring.cloud.gcp.sql.instance-connection-name=xxx:europe-west4:xxx
spring.cloud.gcp.logging.enabled=true

The compilation is successful, no problems there. The problem occurs when I want to access my Spring Boot application. I constantly get a 502 Error. There is nothing in the logs that gives me a clue on what is wrong:

A 2020-01-20T16:14:17Z   .   ____          _            __ _ _

A 2020-01-20T16:14:17Z  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \

A 2020-01-20T16:14:17Z ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \

A 2020-01-20T16:14:17Z  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )

A 2020-01-20T16:14:17Z   '  |____| .__|_| |_|_| |_\__, | / / / /

A 2020-01-20T16:14:17Z  =========|_|==============|___/=/_/_/_/

A 2020-01-20T16:14:17Z  :: Spring Boot ::        (v2.1.5.RELEASE)


com.xxx.api.xxxApplication       : Starting xxxApplication v0.0.1-SNAPSHOT on bc233766746a with PID 1 (/app.jar started by root in /)

com.xxx.api.xxxApplication       : The following profiles are active: gcp

 .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data repositories in DEFAULT mode.

.s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 532ms. Found 17 repository interfaces.

 trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration' of type [org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration$$EnhancerBySpringCGLIB$$2c4dbf14] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration' of type [org.springframework.security.config.annotation.configuration.ObjectPostProcessorConfiguration$$EnhancerBySpringCGLIB$$c4fb874e] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

 trationDelegate$BeanPostProcessorChecker : Bean 'objectPostProcessor' of type [org.springframework.security.config.annotation.configuration.AutowireBeanFactoryObjectPostProcessor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

 trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler@6b00f608' of type [org.springframework.security.access.expression.method.DefaultMethodSecurityExpressionHandler] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

 trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration' of type [org.springframework.security.config.annotation.method.configuration.GlobalMethodSecurityConfiguration$$EnhancerBySpringCGLIB$$e9d02a00] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

 trationDelegate$BeanPostProcessorChecker : Bean 'methodSecurityMetadataSource' of type [org.springframework.security.access.method.DelegatingMethodSecurityMetadataSource] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

 trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.hateoas.config.HateoasConfiguration' of type [org.springframework.hateoas.config.HateoasConfiguration$$EnhancerBySpringCGLIB$$abce0c46] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

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.19]

o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
 o.s.web.context.ContextLoader            : Root WebApplicationContext: initialization completed in 11326 ms

com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...

Connecting to Cloud SQL instance [xxx:europe-west4:xxx] via SSL socket.

First Cloud SQL connection, generating RSA key pair.

This is the last lines I have in the logs. Nothing seems to break, no errors as far as I can tell. It seems to correctly connect to the Cloud SQL instance. I'm lost here. I've tried a lot of things, but I always get a 502 request from Spring Boot no matter what.

For information, the /liveness_check and /readiness_check always return 200 even when the server is not launched (which is strange...).

Tell me if you need any more informations on the configuration I am using. Thank you in advance!


Solution

  • We finally solved our issue. For those who might have the same issue:

    The problem was caused by our guava version. We add the version 18.0, which was problematic apparently. We added the following dependencies in the pom.xml:

    <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>28.2-jre</version>
            </dependency>
    

    And the problem was solved :)