configuring HTTP endpoint to shutdown a spring boot web application - spring-boot

I have a Spring boot application running. Referring https://stackoverflow.com/a/36275797/6038386 to gracefully shut down the server, I included all changes in my pom.xml and application.properties.
Problem is when I am running spring boot server on one terminal (It starts successfully as expected) and try to shut it down using command: curl -X POST localhost:8000/shutdown on another terminal, server still keeps running. It is not shutting down. On my local, I don't see any logs or exception when i hit this shutdown command.
**
Can someone please help me to figure out, what is missing in my
configuration.
**
Note: When I tried to shut down the server using Jenkins job having same command (and running jenkins server had same pom and properties as my local), i got following exception: {"timestamp":1515145896307,"status":500,"error":"Internal Server Error","exception":"java.lang.NoClassDefFoundError","message":"org/springframework/boot/actuate/endpoint/ShutdownEndpoint$1","path":"/shutdown"}
My pom.xml is as follows:
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.samples</groupId>
<artifactId>AllergiesConditions</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<!-- Generic properties -->
<java.version>1.7</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<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>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.2</version>
</dependency>
<!-- Exclude Spring Boot's Default Logging -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
</dependency>
</dependencies>
<build>
<finalName>AllergiesConditions</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
my application.properties includes following lines:
server.port=8000
endpoints.shutdown.sensitive=false
endpoints.shutdown.enabled=true

With the 1.5 version of spring boot , i think there is no sure shutdown mechanism.
You can see check this link and follow how to properly shutdown with jmx or http, https://github.com/corentin59/spring-boot-graceful-shutdown in your application.
good Luck

Answering my own question:
Actually it was a silly mistake. I was just copy pasting the stuff from
https://stackoverflow.com/a/36275797/6038386 without actually understanding it.
I had included server.contextPath=/AllergiesConditions in my application.properties
So now command to shutdown would become: curl -X POST localhost:8080/AllergiesConditions/shutdown
Another mistake I did was that, I didn't post my full application.properties in question's description, so actually no one could help.

Related

reactor/netty/resources/ConnectionProvider.fixed(Ljava/lang/String;IJLjava/time/Duration;)Lreactor/netty/resources/ConnectionProvider;

spring boot application starts up fails with Azure cosmos DB
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
com.azure.cosmos.implementation.http.HttpClient.createFixed(HttpClient.java:56)
The following method did not exist:
reactor.netty.resources.ConnectionProvider.fixed(Ljava/lang/String;IJLjava/time/Duration;)Lreactor/netty/resources/ConnectionProvider;
The method's class, reactor.netty.resources.ConnectionProvider, is available from the following locations:
jar:file:/Users/vishnuvuyyur/.m2/repository/io/projectreactor/netty/reactor-netty-core/1.0.1/reactor-netty-core-1.0.1.jar!/reactor/netty/resources/ConnectionProvider.class
The class hierarchy was loaded from the following locations:
reactor.netty.resources.ConnectionProvider: file:/Users/vishnuvuyyur/.m2/repository/io/projectreactor/netty/reactor-netty-core/1.0.1/reactor-netty-core-1.0.1.jar
Reason for the error:
As in the logs it states :com.azure.cosmos.implementation.http.HttpClient.createFixed(HttpClient.java:56)
The azure cosmos library is not updated with the latest spring boot version
Current issue can be reproduced with spring-boot 2.4.0 and azure cosmos db 3.0.0-beta.1
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.3.RELEASE</version>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-cosmosdb-spring-boot-starter</artifactId>
<version>3.0.0-beta.1</version>
Fix, lower the spiring boot version to 2.3.5 since azure db version 3.0.0-beta.1 dosen't support spring 2.4.0
Changing the spring boot version worked for me
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/>
</parent>
I've solved using java 11, i created webflux from intellij for reactive microservices.
<?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.4.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.api.bank.salesforce</groupId>
<artifactId>sbs</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>sbs</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>spring-data-cosmosdb</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.10.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.21</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.10.3</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
</dependency>
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>1.5.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.projectreactor.netty</groupId>
<artifactId>reactor-netty</artifactId>
<version>0.9.2.RELEASE</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>io.swagger.codegen.v3</groupId>
<artifactId>swagger-codegen-maven-plugin</artifactId>
<version>3.0.18</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/library-api.yaml</inputSpec>
<language>spring</language>
<output>${project.build.directory}/generated-sources/</output>
<generateSupportingFiles>false</generateSupportingFiles>
<apiPackage>com.api.bank.salesforce.sbs.api</apiPackage>
<modelPackage>com.api.bank.salesforce.sbs.models</modelPackage>
<configOptions>
<interfaceOnly>true</interfaceOnly>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Spring JAR file very big, although project very smal

I have a small Spring Boot project where I use a Spring Cloud Function to deploy on AWS.
What does the App do?
Function as Endpoint
Connect and write some small Data to DynamoDB Database
forward to an URL (Statuscode 302)
When packaging that project as jar file, I get an 40,3 MB big file...
When deploying that file to AWS as Lambda (cloud function), it takes up to 20-30 seconds for a cold start - too much!
For my case the user gets to a web page after the lambda is called...it´s not nice letting the user wait 20-30 seconds to get to a web page.
here is my 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.3.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Hoxton.SR6</spring-cloud.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-function-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-compiler</artifactId>
</dependency>
<!-- AWS DynamoDb -->
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
</dependency>
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>5.1.0</version>
</dependency>
<!-- AWS Lambda Dependencies -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-function-adapter-aws</artifactId>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>3.1.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>
</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>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<finalName>MyProject-prod</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot.experimental</groupId>
<artifactId>spring-boot-thin-layout</artifactId>
<version>1.0.25.RELEASE</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>aws</shadedClassifierName>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Is there something missing to get a very thin and small jar for invoking a cloud function?
Thanks!
As best practice, I would not recommend using 'Spring' inside Java program deployed as a Lambda function. Java runtime itself doesn't have good 'start', not inject 'Spring' is heavier.
Please advice any reason you have to use Spring Boot in this case.
And to avoid cold-start for Lambda, what I'm doing is I create a Cloudwatch Rule, for an interval like 5 seconds, it hits Lambda with a 'warn-up' parameters to warm the lambda.
If you know the time frame your lambda needs to be warn, you can configure the CloudWatch rules accordingly.
Let me know if more questions.

Spring Boot /actuator returns 404 not found

I am using spring boot 2.1.4.RELEASE and currently trying to access http://localhost:8080/actuator but i am getting 404 not found. I am not sure what am i doing wrong here. Below is my pom dependencies-
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dir</groupId>
<artifactId>api</artifactId>
<version>2.4.0</version>
<packaging>jar</packaging>
<name>Search</name>
<description>Search</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<distributionManagement>
<repository>
<id>Releases</id>
<name>repo1.releases</name>
<url>http://www.something.com</url>
</repository>
<snapshotRepository>
<id>Snapshots</id>
<name>repo1.com</name>
<url>http://repo1.com/artifactory/Snapshots</url>
</snapshotRepository>
</distributionManagement>
<properties>
<!--These two should be in all ParentPOMs -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Keep this version in sync with the pom's version ignoring "-SNAPSHOT" -->
<applicationVersion>1.0.0</applicationVersion>
<elasticsearch.version>5.2.0</elasticsearch.version>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</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-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webflux</artifactId>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.7</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>x-pack-transport</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.2.0</version>
</dependency>
<dependency>
<groupId>apache-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.7.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- Spring boot actuator to expose metrics endpoint -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<!-- Micormeter core dependecy -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-core</artifactId>
</dependency>
<!-- Micrometer Prometheus registry -->
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<environmentVariables>
<version>9.9.9</version>
<basePath>http://sample-basepath.com</basePath>
</environmentVariables>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</build>
</project>
properties file config
management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
management.endpoint.health.show-details=always
management.endpoint.beans.enabled=true
when i run the application i do see this in console
2019-04-27 00:04:25.406 INFO 32522 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 16 endpoint(s) beneath base path '/actuator'
2019-04-27 00:04:25.534 INFO 32522 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path '/myendpoint'
Please check if you have configured server.servlet.contextPath=/myendpoint
If you have done like this please try localhost:8080/{server.servlet.contextPath}/actuator
Spring boot Actuator URL changing through SpringBoot Releases,
Initially we can Access Actuator URL with https://localhost:8080/actuator
in early milestone versions of springboot 2.0.0 the URL is https://localhost:8080/application
Now current springboot version it can be access through https://localhost:8080/actuator
Certain actuator endpoints are disabled, and have to be enabled before you can use them. I was trying to access /actuator/beans, which turns out to be just such an endpoint. According to the docs, all you need is to enable them in your application.properties file:
management.endpoints.web.exposure.include=health,info,beans
As per above answers Try
http://localhost:8080/<server.servlet.context-path>/actuator/
but if it show error so there would be these possible reason is that you not include dependency in you pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
I'm using a spring boot.
I got this simple message from spring boot.😇
Spring Boot /actuator returns 404 not found
here is my application.yml file.
server:
port: 6150
servlet:
context-path: /
management:
server:
port: 6150
endpoints:
web:
base-path: /actuator
exposure:
include: "*"
and then:
http://localhost:6150/actuator
I know this question is quit old and some situation(condition) is different.
I hopefully someone save their time.
I had the same 404 error, even after exactly following Spring documentation. What finally worked for me was deleting actuator dependency and the jar, and adding it again, with a mvn clean install. It worked :)
I had a similar problem, but my issue was that the following application property was set in my project:
management:
endpoints:
web:
base-path: /
Which meant that the actual endpoint for something like:
http://localhost:8080/actuator/beans
was in fact:
http://localhost:8080/beans
I think there is a context path /myendpoint in your application.
Please try with this endpoint
http://localhost:8080/myendpoint/actuator
This was the first result when I googled a similar issue I was having. Unfortunately none of the solutions above worked for me but another source mentioned that I needed to set the management port:
management.server.port=8080
Which allows me to hit
http://localhost:8080/actuator/
Because you misunderstand.
Exposed endpoints are in two ways, please read carefully in the docs. One is exposed to JMX, while the other is exposed to WEB.
Obviously, if you enable the beans endpoint, it only expose to JMX.
If you are getting 401 unauthorised then you should add roll "ACTUATOR" in your token, then only you will be able to hit /actuator endpoints of your application.
It was a version conflict for me which was why the actuator endpoints were not exposed. I removed the version from the pom file for spring-boot-starter-actuator to make it work
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<!--<version>1.5.6.RELEASE</version>-->
</dependency>
For my project, the problem could be resolved by adding the maven-clean-plugin. In the project, I am using the spring-boot-maven-plugin like this:
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<outputDirectory>./out</outputDirectory>
</configuration>
I was not able to view any indicator until using the maven-clean-plugin:
<artifactId>maven-clean-plugin</artifactId>
<configuration>
<filesets>
<fileset>
<directory>./out</directory>
</fileset>
</filesets>
</configuration>
I solved for spring 2.6.x with a bean
#Bean
public HttpTraceRepository httpTraceRepository() {
return new InMemoryHttpTraceRepository();
}
as aware for the project instructions on the link: Spring-Boot-2.2.0-M3-Release-Notes

Error when deploy Spring Boot application in Google AppEngine + Non Zero Exit 2

I am getting below error when deploying my test maven Spring Boot REST app in GAE -
[ERROR] Failed to execute goal com.google.cloud.tools:appengine-maven-plugin:2.0.0-rc5:deploy (default-cli) on project PublicLibrary: App Engine application deployment failed: com.google.cloud.tools.appengine.operations.cloudsdk.process.ProcessHandlerException: com.google.cloud.tools.appengine.AppEngineException: Non zero exit: 2 -> [Help 1]
App.yaml looks like
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
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 http://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.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.publiclibrary</groupId>
<artifactId>PublicLibrary</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>PublicLibrary</name>
<description>Demo project for Spring data relationship</description>
<properties>
<java.version>1.8</java.version>
</properties>
<profiles>
<profile>
<id>cloud-gcp</id>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-gcp-starter</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.0.0-rc5</version>
<configuration>
<deploy.projectId>libraryapi-03312019</deploy.projectId>
<deploy.version>1.0</deploy.version>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>25.0-jre</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</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>
<exclusions>
<exclusion>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
I would appreciate any help.
Check the official Springboot sample of Google Cloud Platform to see what you might be doing different.
For example, I see that in the <properties> section it requires <maven.compiler.source> and <maven.compiler.target>:
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source> <!-- REQUIRED -->
<maven.compiler.target>${java.version}</maven.compiler.target> <!-- REQUIRED -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<appengine.maven.plugin>1.3.2</appengine.maven.plugin>
</properties>
Note that you are using version 2.0.0-rc5 for the appengine-maven-plugin so if you add it in the properties like above you should use the same version as in the plugin section:
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.maven.plugin}</version>
</plugin>
Thanks. I followed the sample app and add the differences to my pom.xml. That alone didn't fix the issue. Additionally, I added legacy health checks that to app.yaml that allowed to deploy the app (which took quite some time) -
health_check:
enable_health_check: True
check_interval_sec: 5
timeout_sec: 4
unhealthy_threshold: 2
healthy_threshold: 2
But after deployment when I try to access the app as https://< project-id>:appspot.com I get below error -
Error: Server Error
The server encountered a temporary error and could not complete your request.
Please try again in 30 seconds.
UPDATE
I added the resources section to app.yaml as in GAE Java is known to consume high memory as identified in this article
resources:
cpu: 2
memory_gb: 2.3
disk_size_gb: 10
volumes:
- name: ramdisk1
volume_type: tmpfs
size_gb: 0.5

Spring application shut down at startup

I have this strange behaviour with my spring boot application where suddently the startup process doesn't work anymore. Here's the all the log:
I really can't say what's wrong since it stopped working. I also fetched on git the remote version of the code that is deployed and working right now. I use Intellij Idea as IDE, I have already restarted the IDE and the laptop.
I looked over the Internet but everyone having this issue has problems abot pom or dependency. I can't get a clue from the logs. Thanks in advance.
EDIT: Here is my pom.xml
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>it.reag</groupId>
<artifactId>reag-common-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>reag-mailsender-batch</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>it.reag</groupId>
<artifactId>reag-common-api-model</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>6.1.0.jre8</version>
</dependency>
</dependencies>
<build>
<finalName>MailSenderBatch</finalName>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Note that if I change the spring-boot-starter dependency with spring-boot-starter-web the app works, but I don't understand why. I don't use any of the feature of web environment. Also, it worked perfectly until the other day with the spring-boot-starter dependency.
Leaving this answer as it may help others. If one defines a parent in pom like you have here:
<parent>
<groupId>it.reag</groupId>
<artifactId>reag-common-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
Then a simple dependency of spring-boot-starter-web in this module pom may not be the same as you expected, it may be customized in parent, aka reag-common-api pom, servlet container may be removed there. This happens because of dependency hierachy rule in maven. In this way, in order to verify that a missing container is the reason why spring application starts and quits, one can use mvn dependency:tree to see if a tomcat or undertow or netty is shown as a container (not an exact expression).
In my project, this would be neede for submodule pom:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-undertow</artifactId>
</dependency>
As its parent has this:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>

Resources