Spring Boot on Microsoft Azure

When running Spring Boot web apps on PaaS, I've mainly used Heroku and Cloud Foundry (PWA, etc.) because it's "easy". However, when I was researching Microsoft Azure the other day, I found an official document that it can be easily deployed to App Service, so I tried it.

https://docs.microsoft.com/ja-jp/java/azure/spring-framework/deploy-spring-boot-java-app-with-maven-plugin

When I tried it, it was really "easy"! 2018-09-14_23h01_12.png

I have deployed it with a simpler procedure than the above document, so I will summarize it. The main differences in the procedure are as follows.

--Based on Spring Initializr --Deploy as jar instead of war --Do not add tomcat dependency --Do not use SpringBootServletInitializer inheritance

Click here for the code. https://github.com/kikutaro/AzureSpringBoot

Development environment

procedure

Spring Boot project creation

Create using "** Spring Initializr Java Support **" in the Visual Studio Code extension.

** Select "View" **-> ** "Command Palette" ** 2018-09-13_20h52_50.png

MS documentation is Maven based, so select ** "Spring Initializr: Generate a Maven Project" ** 2018-09-12_23h14_23.png

Select Java 2018-09-12_23h14_49.png

Enter the GroupId. I chose "tech.kikutaro". 2018-09-14_22h20_39.png

Enter the ArtifactId. I chose "azure spring boot". 2018-09-14_22h21_32.png

Select 2.0.5 for Spring Boot 2018-09-12_23h18_40.png

Select two dependencies, Web and DevTools 2018-09-12_23h18_59.png

2018-09-12_23h19_18.png

that's all. After saving, the following dialog will be displayed. Open it with "Open it". 2018-09-12_23h36_28.png

Operation check

Before deploying to Azure, write a simple code and check the operation at hand. Here, the code is just to return "Hello, Azure!" In REST GET.

DemoApplication.java


import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
public class DemoApplication {

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

	@GetMapping("/hello")
	public String hello() {
		return "Hello, Azure!";
	}
}

Confirm the startup.

.\mvnw.cmd clean package
.\mvnw.cmd spring-boot:run

It is OK if you can access the local environment and check the operation.

2018-09-13_00h10_16.png

Ready to deploy to Azure

MS's document wars packaging I have devised to make it work with other Servlets such as jetty, such as changing to, adding tomcat dependency, inheriting SpringBootServletInitializer, but this time I proceeded without changing this area in particular. ..

Actually, the following settings are not required, but I added it this time to prevent the URL of the deployed application from colliding.

pom.xml


<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <!-- add from -->
    <maven.build.timestamp.format>yyyyMMddHHmm</maven.build.timestamp.format>
    <!-- add to -->
</properties>

Add the settings for azure-webapp-maven-plugin. The documentation says "<!-Check latest version on Maven Central->".

In addition, when I tried using 1.1.0 as the first document and setting the deploymentType to jar, an error occurred. It seems that deploymentType does not support jar.

2018-09-14_23h16_29.png

With the latest 1.4.0, I was able to specify the jar without any problems.

pom.xml


<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
	</plugin>
	<!-- add from -->
	<plugin>
	    <groupId>com.microsoft.azure</groupId>
	    <artifactId>azure-webapp-maven-plugin</artifactId>
	    <version>1.4.0</version>
	    <configuration>
	        <resourceGroup>maven-projects</resourceGroup>
	        <appName>${project.artifactId}-${maven.build.timestamp}</appName>
        	<region>westus</region>
	        <javaVersion>1.8</javaVersion>
	        <deploymentType>jar</deploymentType>
	        </configuration>
        </plugin>
        <!-- add to -->
    </plugins>
</build>

Deploy to Azure

I installed Azure CLI before deploying.

When you log in with the Azure CLI, the browser will start automatically and the login screen will be displayed. Enter your username and password to log in.

python


az login

All you have to do is deploy.

.\mvnw.cmd clean package
.\mvnw.cmd azure-webapp:deploy

Wait for the deployment to complete. 2018-09-14_23h44_07.png

If successful, open the Azure App Service to see the deployed application.

2018-09-14_23h12_54.png

After selecting the application, click the URL link displayed in the upper right to open the created page.

2018-09-14_23h14_45.png

moved!

2018-09-14_23h01_12.png

It looks long because I wrote the procedure in detail, but it was as easy as deploying to Heroku etc.

Recommended Posts

Spring Boot on Microsoft Azure
Try Spring Boot on Mac
gRPC on Spring Boot with grpc-spring-boot-starter
Try running Spring Boot on Kubernetes
Create Spring Boot development environment on Vagrant
Minimal configuration to run Spring Boot application on Azure Web Apps
Spring Boot environment construction memo on mac
Challenge Spring Boot
Spring Boot Form
Spring Boot Memorandum
gae + spring boot
Deploy a Spring Boot application on Elastic Beanstalk
SPRING BOOT learning record 01
Spring Boot + Heroku Postgres
Spring boot memo writing (1)
First Spring Boot (DI)
SPRING BOOT learning record 02
Spring Boot2 cheat sheet
Spring Boot exception handling
Sign in to a Spring Boot web application on the Microsoft ID platform
Spring Boot Servlet mapping
Spring boot development-development environment-
Spring Boot learning procedure
Learning Spring Boot [Beginning]
Spring boot memo writing (2)
Spring Boot 2.2 Document Summary
[Spring Boot] DataSourceProperties $ DataSourceBeanCreationException
Spring Boot 2.3 Application Availability
Spring boot tutorials Topics
Download with Spring Boot
Deploy the Spring Boot project to Tomcat on XAMPP
[Spring Boot] Environment construction (macOS)
Set context-param in Spring Boot
Try Spring Boot from 0 to 100.
Generate barcode with Spring Boot
Hello World with Spring Boot
Implement GraphQL with Spring Boot
Spring Boot tutorial task schedule
Spring 5 & Spring Boot 2 Hands-on preparation procedure
Get started with Spring boot
Hello World with Spring Boot!
Spring Boot 2 multi-project in Gradle
[Spring Boot] Web application creation
[Java] Deploy the Spring Boot application to Azure App Service
spring boot port duplication problem
Run LIFF with Spring Boot
SNS login with Spring Boot
Spring Boot Hot Swapping settings
[Java] Thymeleaf Basic (Spring Boot)
Introduction to Spring Boot ① ~ DI ~
File upload with Spring Boot
Spring Boot starting with copy
Introduction to Spring Boot ② ~ AOP ~
CICS-Run Java application-(4) Spring Boot application
Spring Boot starting with Docker
Spring Boot + Springfox springfox-boot-starter 3.0.0 Use
[Spring Security] Spring Security on GAE (SE)
Spring Boot DB related tips
Hello World with Spring Boot
Set cookies with Spring Boot
[Spring Boot] Easy paging recipe