Showing posts with label Spring Boot Maven Google Cloud. Show all posts
Showing posts with label Spring Boot Maven Google Cloud. Show all posts

Saturday, October 14, 2017

Getting started with Spring Boot deployed on Google Cloud. Maven, Google CloudSDK installation



This post will explain you. How to deploy springboot application on google cloud

Step 1: Open Open Google Cloud


Step 2: Login into google cloud.
Step 3: Register Cloud application with free trail - Cloud Application Registration

Step 4:Create a new Project -
Provide necessary details and signup the same.
Step 5: Now you are completed signup process . Spring boot application needs to be deployed.
Step 6: Create a maven java project with name - helloworld-springboot and below code to pom.xml file.


  4.0.0

  com.java.gcloud.springboot
  helloworld-springboot
  0.0.1-SNAPSHOT
  jar

  helloworld-springboot
  Demo project for Spring Boot with google cloud

 

  
    1.8
    ${java.version} 
    ${java.version} 
    UTF-8
    1.3.1
  

  
    
      org.springframework.boot
      spring-boot-starter-web
      1.5.7.RELEASE
    
  

  
    
      
        org.springframework.boot
        spring-boot-maven-plugin
        1.5.7.RELEASE
        
          
            
              repackage
            
          
        
      

      
        com.google.cloud.tools
        appengine-maven-plugin
        ${appengine.maven.plugin}
      

    
  
  
    



Step 7: Now we need to write controller class name HelloworldApplication.java
package com.java.gcloud.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class HelloworldApplication {
  @RequestMapping("/")
  public String home() {
    return "Hello World.. Welcome to Spring Boot.. which is deployed on Google cloud appengine!";
  }

  @RequestMapping(value = "/add/{a}/{b}", method = RequestMethod.GET)
  public String add(@PathVariable("a") int a,@PathVariable("b") int b) {
    return "Addition of a["+a+"] and b ["+b+"]is   ======   " + (a+b) ;
  }
  
  @RequestMapping(value = "/substract/{a}/{b}", method = RequestMethod.GET)
  public String substract(@PathVariable("a") int a,@PathVariable("b") int b) {
    return "Substract of a["+a+"] and b ["+b+"]is   ======   " + (a-b) ;
  }
  
  @RequestMapping(value = "/multiply/{a}/{b}", method = RequestMethod.GET)
  public String multiply(@PathVariable("a") int a,@PathVariable("b") int b) {
    return "Multiply of a["+a+"] and b ["+b+"]is   ======   " + (a*b) ;
  }
  
  @RequestMapping(value = "/division/{a}/{b}", method = RequestMethod.GET)
  public String division(@PathVariable("a") int a,@PathVariable("b") int b) {
    return "Division of a["+a+"] and b ["+b+"]is   ======   " + (a/b) ;
  }

  public static void main(String[] args) {
    SpringApplication.run(HelloworldApplication.class, args);
  }
}


Step 8: Run the pom.xml file using mvn clean install
Step 9: Now we need to run the application. go to the directory , where jar created and run the
java -jar   
another way to execute the application is right click on the HelloWorldApplication Run As- JavaApplication.
Step 10: Once spring boot started successfully then go to browser and hit http://localhost:8080 .
you should get the -Hello World.. Welcome to Spring Boot.. which is deployed on Google cloud appengine!

Step 11: That is done. Now we need to deploy this application on google cloud.
Step 12: Install the Google Cloud SDK for windows version and set the PATH in environment variables.
Step 13: Go to the place where pom.xml file is there in command prompt.
gcloud config set project p7259000552 After this command
mvn appengine:deploy

Step 14: You will get Build Success message. So application has been deployed successfully.
Step 15: Verify, whether it has been deployed or not - https://.appspot.com/
Step 16: This application will have simple math operations like add,sustarct,multiply,division if you click any of this links you will get appropriate results.
https://p7259000552.appspot.com/add/20/30
   https://p7259000552.appspot.com/substract/20/30
   https://p7259000552.appspot.com/multiply/20/30
   https://p7259000552.appspot.com/division/20/30
 


Thank you verymuch for viewing this post. If you like please share and comment.

AddToAny

Contact Form

Name

Email *

Message *