×
Community Blog Deploy Spring Boot or Spring Cloud Applications to Alibaba Cloud in Eclipse

Deploy Spring Boot or Spring Cloud Applications to Alibaba Cloud in Eclipse

This article will show you how to deploy a Spring Boot or Spring Cloud application to Alibaba Cloud in Eclipse.

Spring Cloud and Spring Boot are currently the most popular microservice development frameworks. This article will show you how to deploy a Spring Boot or Spring Cloud application to Alibaba Cloud in Eclipse.

Develop an Application Locally

The coding method is similar no matter whether you compile Spring Boot applications that run on the cloud or locally. Therefore, this article takes the Spring Boot application for printing "Hello World" on a Web page as an example to explain the deployment method. In this example, the built-in Tomcat container is started to process the HTTP request and print the string "Hello World" on a Web page.

The built-in Tomcat listens to requests from the root directory

1

package com.aliyun.toolkit.demo;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HelloWorldController {
 
    @RequestMapping("/")
    public String sayHello() {
        return "Alibaba Cloud Toolkit: Hello,World.";
    }
}

Spring Boot startup class

2

package com.aliyun.toolkit.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

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

Download a Spring Boot demo project

The preceding code is a standard Spring Boot project.

Install a Plug-in

Alibaba Cloud provides an Eclipse-based plug-in to help developers efficiently deploy applications written in the local IDE to ECS instances.

URL of the plug-in: https://www.aliyun.com/product/cloudtoolkit_en

The installation process of this Eclipse-based plug-in is similar to that of a common plug-in, and therefore will not be detailed here.

Configure the Plug-in Preferences

After installing the plug-in, configure the preferences by choosing:

Top menu > Window > Preferences > Alibaba Cloud Toolkit > Accounts.

When the following page is displayed, configure the AK and SK of your Alibaba Cloud account to complete the configuration of preferences.( If you are using a RAM user account, enter the AK and SK of the RAM user.)

3

Deploy the Application

4

In Eclipse, right-click the project name and choose Alibaba Cloud > Deploy to ECS from the shortcut menu. The following deployment window is displayed:

5

In the Deployment Configurations dialog box, set the deployment parameters, and click Deploy to deploy the application.

Description of Deployment Parameters:

  • Deploy File: Two options are available.
  • Maven Build: If Maven is used to build the current project, you can use Alibaba Cloud Toolkit to directly build and deploy the application.
  • Upload File: If Maven is not used to build the current project, or a locally packaged deployment file already exists, you can select and directly upload the local deployment file.
  • Target Deploy ECS: Select a region from the drop-down list, and then select the ECS instance to be deployed in the region.
  • Deploy Location: Enter the deployment path on the ECS instance, for example, /root/springbootdemo.
  • Command: Enter the application startup command, for example, sh /root/springbootdemo/restart.sh. This is the command to be executed after the application package is deployed. For a Spring Boot program, this is usually a startup command: java -jar XXXX.jar.

The /root/springbootdemo/restart.sh file contains the following content:

source ~/.bash_profile
killall java
nohup java -jar /root/springbootdemo/springbootdemo-0.0.1-SNAPSHOT.jar > nohup.log 2>&1 &
0 0 0
Share on

Nick(倪超)

9 posts | 1 followers

You may also like

Comments

Nick(倪超)

9 posts | 1 followers

Related Products