GithubHelp home page GithubHelp logo

dalalsunil1986 / gae-java8-springboot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sophea/gae-java8-springboot

0.0 0.0 0.0 133 KB

backend springboot java with GAE standard environment

License: GNU General Public License v3.0

Java 28.72% HTML 8.45% JavaScript 62.83%

gae-java8-springboot's Introduction

SpringBoot backend APIs for App Engine Standard (Java 8)

This sample demonstrates how to deploy a Spring Boot application on Google App Engine.

See the Google App Engine standard environment documentation for more detailed instructions.

Setup

  • Download and initialize the Cloud SDK

    gcloud init

  • Create an App Engine app within the current Google Cloud Project

    gcloud app create

Maven

Running locally

mvn appengine:devserver

To use vist: http://localhost:8080/

Deploying

mvn appengine:update

To use vist: https://YOUR-PROJECT-ID.appspot.com

Testing

mvn verify

As you add / modify the source code (src/main/java/...) it's very useful to add unit testing to (src/main/test/...). The following resources are quite useful:

For further information, consult the Java App Engine documentation.

Steps to convert a Spring Boot application for App Engine Standard

Use the WAR packaging

You must use WAR packaging to deploy into Google App Engine Standard.

If you generate a Spring Boot project from start.spring.io, make sure you switch to the full version view of the initializer site, and select WAR packaging.

If you have an existing JAR packaging project, you can convert it into a WAR project by:

  1. In pom.xml, change <packaging>jar</packaging> to <packaging>war</packaging>
  2. Create a new SpringBootServletInitializer implementation:
public class ServletInitializer extends SpringBootServletInitializer {
  @Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  return application.sources(YourApplication.class);
  }
}

Remove Tomcat Starter

Google App Engine Standard deploys your WAR into a Jetty server. Spring Boot's starter includes Tomcat by default. This will introduce conflicts. Exclude Tomcat dependencies:

<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>

Do not include the Jetty dependencies. But you must include Servlet API dependency:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
  <scope>provided</scope>
</dependency>

Add App Engine Standard Plugin

In the pom.xml, add the App Engine Standard plugin:

<plugin>
  <groupId>com.google.cloud.tools</groupId>
  <artifactId>appengine-maven-plugin</artifactId>
  <version>1.3.1</version>
</plugin>

This plugin is used to run local development server as well as deploying the application into Google App Engine.

Add App Engine Configuration

Add a src/main/webapp/WEB-INF/appengine-web.xml:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">

    <application>${gae.application.id}</application>
    <version>${gae.application.version}</version>

    <public-root>/public</public-root>
    
    <runtime>java8</runtime>
    <sessions-enabled>false</sessions-enabled>
    <threadsafe>true</threadsafe>
    
</appengine-web-app>

This configure is required for applications running in Google App Engine.

Exclude JUL to SLF4J Bridge

Spring Boot's default logging bridge conflicts with Jetty's logging system. To be able to capture the Spring Boot startup logs, you need to exclude org.slf4j:jul-to-slf4j dependency. The easiest way to do this is to set the dependency scope to provided, so that it won't be included in the WAR file:

<!-- Exclude any jul-to-slf4j -->
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>jul-to-slf4j</artifactId>
  <scope>provided</scope>
</dependency>

Run the application locally

  1. Set the correct Cloud SDK project via gcloud config set project YOUR_PROJECT to the ID of your application.
  2. Run mvn spring-boot:run
  3. Visit http://localhost:8080
  4. Visit http://localhost:8080/api/categories/v1/all
  5. Visit http://localhost:8080/api/categories/v1/{id}

Deploy to App Engine java8 standard environment

  1. mvn appengine:update
  2. Visit http://YOUR_PROJECT.appspot.com.

gae-java8-springboot's People

Contributors

sophea avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.