- Spring Boot - Google OAuth2 Sign-In
- Spring Boot - Google Cloud Platform
- Spring Boot - OAuth2 with JWT
- Securing Web Applications
- Spring Boot - Database Handling
- Rest Controller Unit Test
- Spring Boot - Unit Test Cases
- Spring Boot - Twilio
- Spring Boot - Apache Kafka
- Spring Boot - Batch Service
- Spring Boot - Web Socket
- Spring Boot - Hystrix
- Spring Boot - Sending Email
- Spring Boot - Flyway Database
- Tracing Micro Service Logs
- Spring Boot - Creating Docker Image
- Spring Boot - Enabling Swagger2
- Spring Boot - Admin Client
- Spring Boot - Admin Server
- Spring Boot - Actuator
- Spring Cloud Configuration Client
- Spring Cloud Configuration Server
- Zuul Proxy Server and Routing
- Service Registration with Eureka
- Spring Boot - Eureka Server
- Spring Boot - Enabling HTTPS
- Spring Boot - Scheduling
- Spring Boot - Internationalization
- Spring Boot - CORS Support
- Consuming RESTful Web Services
- Spring Boot - Thymeleaf
- Spring Boot - Service Components
- Spring Boot - File Handling
- Spring Boot - Rest Template
- Spring Boot - Tomcat Port Number
- Spring Boot - Servlet Filter
- Spring Boot - Interceptor
- Spring Boot - Exception Handling
- Building RESTful Web Services
- Spring Boot - Logging
- Spring Boot - Application Properties
- Spring Boot - Runners
- Spring Beans & Dependency Injection
- Spring Boot - Code Structure
- Spring Boot - Build Systems
- Spring Boot - Tomcat Deployment
- Spring Boot - Bootstrapping
- Spring Boot - Quick Start
- Spring Boot - Introduction
- Spring Boot - Home
Spring Boot Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Spring Boot - Google Cloud Platform
Google Cloud Platform provides a cloud computing services that run the Spring Boot apppcation in the cloud environment. In this chapter, we are going to see how to deploy the Spring Boot apppcation in GCP app engine platform.
First, download the Gradle build Spring Boot apppcation from Spring Initiapzer page
. Observe the following screenshot.Now, in build.gradle file, add the Google Cloud appengine plugin and appengine classpath dependency.
The code for build.gradle file is given below −
buildscript { ext { springBootVersion = 1.5.9.RELEASE } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") classpath com.google.cloud.tools:appengine-gradle-plugin:1.3.3 } } apply plugin: java apply plugin: ecppse apply plugin: org.springframework.boot apply plugin: com.google.cloud.tools.appengine group = com.tutorialspoint version = 0.0.1-SNAPSHOT sourceCompatibipty = 1.8 repositories { mavenCentral() } dependencies { compile( org.springframework.boot:spring-boot-starter-web ) testCompile( org.springframework.boot:spring-boot-starter-test ) }
Now, write a simple HTTP Endpoint and it returns the String success as shown −
package com.tutorialspoint.appenginedemo; import org.springframework.boot.SpringApppcation; import org.springframework.boot.autoconfigure.SpringBootApppcation; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApppcation @RestController pubpc class AppengineDemoApppcation { pubpc static void main(String[] args) { SpringApppcation.run(AppengineDemoApppcation.class, args); } @RequestMapping(value = "/") pubpc String success() { return "APP Engine deployment success"; } }
Next, add the app.yml file under src/main/appengine directory as shown −
runtime: java env: flex handlers: - url: /.* script: this field is required, but ignored
Now, go to the Google Cloud console and cpck the Activate Google cloud shell at the top of the page.
Now, move your source files and Gradle file into home directory of your google cloud machine by using google cloud shell.
Now, execute the command gradle appengineDeploy and it will deploy your apppcation into the Google Cloud appengine.
Note − GCP should be bilpng enabled and before deploying your apppcation into appengine, you should create appengine platform in GCP.
It will take few minutes to deploy your apppcation into GCP appengine platform.
After build successful you can see the Service URL in console window.
Now, hit the service URL and see the output.
Google Cloud SQL
To connect the Google Cloud SQL into your Spring Boot apppcation, you should add the following properties into your apppcation.properties file.
JDBC URL Format
jdbc:mysql://google/<DATABASE-NAME>?cloudSqlInstance = <GOOGLE_CLOUD_SQL_INSTANCE_NAME> &socketFactory = com.google.cloud.sql.mysql.SocketFactory&user = <USERNAME>&password = <PASSWORD>
Note − The Spring Boot apppcation and Google Cloud SQL should be in same GCP project.
The apppcation.properties file is given below.
spring.dbProductService.driverClassName = com.mysql.jdbc.Driver spring.dbProductService.url = jdbc:mysql://google/PRODUCTSERVICE?cloudSqlInstance = springboot-gcp-cloudsql:asia-northeast1:springboot-gcp-cloudsql-instance&socketFactory = com.google.cloud.sql.mysql.SocketFactory&user = root&password = rootspring.dbProductService.username = root spring.dbProductService.password = root spring.dbProductService.testOnBorrow = true spring.dbProductService.testWhileIdle = true spring.dbProductService.timeBetweenEvictionRunsMilps = 60000 spring.dbProductService.minEvictableIdleTimeMilps = 30000 spring.dbProductService.vapdationQuery = SELECT 1 spring.dbProductService.max-active = 15 spring.dbProductService.max-idle = 10 spring.dbProductService.max-wait = 8000
YAML file users can add the below properties to your apppcation.yml file.
spring: datasource: driverClassName: com.mysql.jdbc.Driver url: "jdbc:mysql://google/PRODUCTSERVICE?cloudSqlInstance=springboot-gcp-cloudsql:asia-northeast1:springboot-gcp-cloudsql-instance&socketFactory=com.google.cloud.sql.mysql.SocketFactory&user=root&password=root" password: "root" username: "root" testOnBorrow: true testWhileIdle: true vapdationQuery: SELECT 1 max-active: 15 max-idle: 10 max-wait: 8000Advertisements