Spring Boot makes it easy create web applications quickly
and simply. From the Spring Boot website;
Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run". We take an opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss. Most Spring Boot applications need very little Spring configuration.
When you’ve created a web application with Spring Boot, you will need somewhere to deploy it. That’s where Microsoft Azure’s App Service comes in.
The
Azure App Service is a fully-managed platform designed to run and scale your
applications effortlessly on Windows or Linux. Azure takes care of the
infrastructure maintenance, load balancing and more so you get to focus your
time on developing code.
There are a few articles out there on how to deploy a Spring
Boot application to the Azure App Service, but I couldn’t find a simple run
through showing the steps – so hopefully this works for folks as they dip their
toes in the water of this stuff!
1. You will need your Spring Boot web application packaged using the mvn package target. If you don’t have a Spring Boot web application at hand, you can use a simple hello world application I created to use as an example for this article.
You can access the hello world application here: https://github.com/cbeech1980/HelloWorld
2. Once you have your application packaged you will need to create your App Service Plan and App Service. Details on how to create these can be found within the Azure documentation.
3. Configure your App within Azure to use Java 8 and the latest version of Tomcat;
4. Connect to your App via FTP in order to upload your Spring Boot application. In order to do this you need to obtain the FTP credentials. These can be found by clicking the Get Publish Profile link from the App home in the Azure Portal;
5. This will download an XML file which contains the information you need. An example of which is below;
6. The username, password and FTP location are highlighted in the example file above. Use this to connect to the App Service.
7. Once connected you yill need to upload the Spring Boot Jar created as part of the mvn package target as well as a web.config file. An example web.config file can be seen below;
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\HelloWorld-0.0.1-SNAPSHOT.jar"">
</httpPlatform>
</system.webServer>
</configuration>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\HelloWorld-0.0.1-SNAPSHOT.jar"">
</httpPlatform>
</system.webServer>
</configuration>
8. FTP the HelloWorld-0.0.1-SNAPSHOT.jar and web.config file to the /site/wwwroot directory
9. Open your browser and browse to the App Home and you should see your Spring Boot application running!
No comments:
Post a Comment