Reputation: 286
I'm facing problem when deploy spring boot application to google app engine flexible env. I just want to deploy only in GAE flexible env, because I already have some service run on that(in the same gcp project). So I want deploy it as a new separate service that I can config dispatch file to run microservice system.
Exception in thread "main" java.lang.IllegalStateException: No Available Context
at com.google.cloud.runtimes.jetty9.DeploymentCheck.lifeCycleStarted(DeploymentCheck.java:46)
at org.eclipse.jetty.util.component.AbstractLifeCycle.setStarted(AbstractLifeCycle.java:179)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:69)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1511)
at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1438)
at java.security.AccessController.doPrivileged(Native Method)
at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1437)
I had tried solution following this post Jetty fails to start spring boot application in appengine flexible
but not success yet.
My pom.xml file in below:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source> <!-- REQUIRED -->
<maven.compiler.target>${java.version}</maven.compiler.target> <!-- REQUIRED -->
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>tomcat-juli</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>web-socket</artifactId>
</exclusion>
</exclusions>
</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-security</artifactId>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<mainClass>com.kevin.SpringJqgridApplication</mainClass>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.6.v20170531</version>
</plugin>
<!-- START plugin -->
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>1.3.1</version>
</plugin>
<!-- END plugin -->
</plugins>
</build>
Can anybody help to fixed this issue? Thanks.
Upvotes: 2
Views: 1074
Reputation: 153
I've run into the same problem a couple times, and there are a few potential solutions:
Do you have a directory/file structure that looks something like this: webapp/WEB-INF/appengine-web.xml
? If you have that file there, and are using the maven plugin to deploy, it may attempt to deploy as standard and cause that IllegalStateException error to be thrown. Solution: remove the webapp
directory entirely (it's used only for AppEngine standard configuration). Personally, this was the solution to the IllegalStateException I was receiving this morning.
I had this same issue on another application, and the solution was to make sure you've got the ServletInitializer required by Jetty in a Spring Boot app in AppEngine. See more on that here.
Are you confident the Spring Boot app runs correctly? I've received this error when failing to provide necessary environment variables, causing issues when the application tries to run. One (working) example might be something like this, ensuring to add the corresponding environment variables to the app.yaml:
app.yaml:
env_variables:
SPRING_PROFILES_ACTIVE: "qa"
application.properties:
spring.profiles.active="${SPRING_PROFILES_ACTIVE}"
For both cases, I didn't include the spring boot jetty dependency, instead my build.gradle looked something like this:
compile(group: 'javax.servlet', name: 'javax.servlet-api', version: '4.0.1')
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '2.0.2.RELEASE') {
// GAE runs on Jetty, not Tomcat, must manually disable
exclude(group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat')
}
compile(group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.0.5.RELEASE')
compile(group: 'com.google.appengine', name: 'appengine-api-1.0-sdk', version: '1.9.63')
compile(group: 'org.projectlombok', name: 'lombok', version: '1.18.2') {
exclude(group: 'org.slf4j', module: 'jul-to-slf4j')
}
Upvotes: 3