Adding migrated Spring articles to repo

This commit is contained in:
Robert McMurray 2017-10-23 10:54:39 -07:00
Родитель 5c9ee8ccc7
Коммит 6b6b13f217
161 изменённых файлов: 3764 добавлений и 28 удалений

Просмотреть файл

@ -0,0 +1,216 @@
---
title: Create a basic Azure web app using Eclipse
description: This tutorial shows you how to use the Azure Toolkit for Eclipse to create a Hello World Web App for Azure.
services: app-service
documentationcenter: java
author: selvasingh
manager: routlaw
editor: ''
ms.assetid: 20d41e88-9eab-462e-8ee3-89da71e7a33f
ms.service: app-service
ms.workload: web
ms.tgt_pltfrm: multiple
ms.devlang: java
ms.topic: article
ms.date: 10/19/2017
ms.author: robmcm;asirveda
---
# Create a basic Azure web app using Eclipse
This tutorial shows how to create and deploy a basic Hello World application to Azure as a Web App by using the [Azure Toolkit for Eclipse]. A basic JSP example is shown for simplicity, but similar steps would be appropriate for a Java servlet, as far as Azure deployment is concerned.
When you have completed this tutorial, your application will look similar to the following illustration when you view it in a web browser:
![Preview of Hello World app][01]
[!INCLUDE [azure-toolkit-for-eclipse-prerequisites](../includes/azure-toolkit-for-eclipse-prerequisites.md)]
## To create a Hello World application
First, we'll start off with creating a Java project.
1. Start Eclipse, and at the menu click **File**, click **New**, and then click **Dynamic Web Project**. (If you don't see **Dynamic Web Project** listed as an available project after clicking **File** and **New**, then do the following: click **File**, click **New**, click **Project...**, expand **Web**, click **Dynamic Web Project**, and click **Next**.)
2. For purposes of this tutorial, name the project **MyWebApp**. Your screen will appear similar to the following:
![Creating a new Dynamic Web Project][02]
3. Click **Finish**.
4. Within Eclipse's Project Explorer view, expand **MyWebApp**. Right-click **WebContent**, click **New**, and then click **JSP File**.
5. In the **New JSP File** dialog box, name the file **index.jsp**, keep the parent folder as **MyWebApp/WebContent**, and then click **Next**.
6. In the **Select JSP Template** dialog box, for purposes of this tutorial select **New JSP File (html)**, and then click **Finish**.
7. When your index.jsp file opens in Eclipse, add in text to dynamically display **Hello World!** within the existing `<body>` element. Your updated `<body>` content should resemble the following example:
```jsp
<body><b><% out.println("Hello World!"); %></b></body>
```
8. Save index.jsp.
## To deploy your application to an Azure Web App Container
There are several ways by which you can deploy a Java web application to Azure. This tutorial describes one of the simplest: your application will be deployed to an Azure Web App Container - no special project type nor additional tools are needed. The JDK and the web container software will be provided for you by Azure, so there is no need to upload your own; all you need is your Java Web App. As a result, the publishing process for your application will take seconds, not minutes.
1. In Eclipse's Project Explorer, right-click **MyWebApp**.
2. In the context menu, select **Azure**, then click **Publish as Azure Web App...**
![Publish as Azure Web App][03]
Alternatively, while your web application project is selected in the Project Explorer, you can click the **Publish** dropdown button on the toolbar and select **Publish as Azure Web App** from there:
![Publish as Azure Web App][14]
3. If you have not already signed into Azure from Eclipse, you will be prompted to sign into your Azure account:
![Azure Sign In dialog box][04]
If you have multiple Azure accounts, some of the prompts during the sign in process may be shown more than once, even if they appear to be the same. When this happens, continue following the sign in instructions.
4. After you have successfully signed into your Azure account, the **Manage Subscriptions** dialog box will display a list of subscriptions that are associated with your credentials. If there are multiple subscriptions listed and you want to work with only a specific subset of them, you may optionally uncheck the ones you do want to use. When you have selected your subscriptions, click **Close**.
![Manage Subscriptions dialog box][05]
5. When the **Deploy to Azure Web App Container** dialog box appears, it will display any Web App containers that you have previously created; if you have not created any containers, the list will be empty.
![Deploy to Azure Web App Container dialog box][06]
6. If you have not created an Azure Web App Container before, or if you would like to publish your application to a new container, use the following steps. Otherwise, select an existing Web App Container and skip to step 7 below.
a. Click **New...**
![Deploy to Azure Web App Container dialog box][15]
b. The **New Web App Container** dialog box will be displayed:
![New Web App Container dialog box][07a]
c. Enter a **DNS Label** for your Web App Container; this will form the leaf DNS label of the host URL for your web application in Azure. (Note that the name must be available and conform to Azure Web App naming requirements.)
d. In the **Web Container** drop-down menu, select the appropriate software for your application.
Currently, you can choose from Tomcat 8, Tomcat 7 or Jetty 9. A recent distribution of the selected software will be provided by Azure, and it will run on a recent distribution of JDK 8 created by Oracle and provided by Azure.
e. In the **Subscription** drop-down menu, select the subscription you want to use for this deployment.
f. In the **Resource Group** drop-down menu, select the Resource Group with which you want to associate your Web App. (Azure Resource Groups allow you to group related resources together so that, for example, they can be deleted together.)
You can select an existing Resource Group (if you have any) and skip to step g below, or use the following these steps to create a new Resource Group:
* Click **New...**
* The **New Resource Group** dialog box will be displayed:
![New Resource Group dialog box][08]
* In the the **Name** textbox, specify a name for your new Resource Group.
* In the the **Region** drop-down menu, select the appropriate Azure data center location for your Resource Group.
* OPTIONAL: By default, a recent distribution of Java 8 will be deployed by Azure automatically to your web app container as your JVM. However, you can specify a different version and distribution of the JVM if your Web App requires it. To specify the JDK for your Web App, click the **JDK** tab, and select one of the following options:
* **Deploy the default JDK offered by Azure Web Apps service**: This option will deploy a recent distribution of Java 8.
* **Deploy a 3rd party JDK available on Azure**: This option allows you to choose from the list of JDKs which are provided by Microsoft Azure.
* **Deploy my own JDK from this download location**: This option allows you to specify your own JDK distribution, which must be packaged as a ZIP file and uploaded to either a publicly available download location or an Azure storage account for which you have access.
![New Web App Container dialog box][07b]
g. Click **OK**.
h. The **App Service Plan** drop-down menu lists the app service plans that are associated with the Resource Group that you selected. (App Service Plans specify information such as the location of your Web App, the pricing tier and the compute instance size. A single App Service Plan can be used for multiple Web Apps, which is why it is maintained separately from a specific Web App deployment.)
You can select an existing App Service Plan (if you have any) and skip to step h below, or use the following these steps to create a new App Service Plan:
* Click **New...**
* The **New App Service Plan** dialog box will be displayed:
![New App Service Plan dialog box][09]
* In the the **Name** textbox, specify a name for your new App Service Plan.
* In the the **Location** drop-down menu, select the appropriate Azure data center location for the plan.
* In the the **Pricing Tier** drop-down menu, select the appropriate pricing for the plan. For testing purposes you can choose **Free**.
* In the the **Instance Size** drop-down menu, select the appropriate instance size for the plan. For testing purposes you can choose **Small**.
i. Once you have completed all of the above steps, the New Web App Container dialog box should resemble the following illustration:
![New Web App Container dialog box][10]
j. Click **OK** to complete the creation of your new Web App container.
Wait a few seconds for the list of the Web App containers to be refreshed, and your newly-created web app container should now be selected in the list.
7. You are now ready to complete the initial deployment of your Web App to Azure:
![Deploy to Azure Web App Container dialog box][11]
Click **OK** to deploy your Java application to the selected Web App container.
By default, your application will be deployed as a subdirectory of the application server. If you want it to be deployed as the root application, check the **Deploy to root** checkbox before clicking **OK**.
8. Next, you should see the **Azure Activity Log** view, which will indicate the deployment status of your Web App.
![Azure Activity Log][12]
The process of deploying your Web App to Azure should take only a few seconds to complete. When your application ready, you will see a link named **Published** in the **Status** column. When you click the link, it will take you to your deployed Web App's home page.
## Updating your web app
Updating an existing running Azure Web App is a quick and easy process, and you have two options for updating:
* You can update the deployment of an existing Java Web App.
* You can publish an additional Java application to the same Web App Container.
In either case, the process is identical and takes only a few seconds:
1. In the Eclipse project explorer, right-click the Java application you want to update or add to an existing Web App Container.
2. When the context menu appears, select **Azure** and then **Publish as Azure Web App...**
3. Since you have already logged in previously, you will see a list of your existing Web App containers. Select the one you want to publish or re-publish your Java application to and click **OK**.
A few seconds later, the **Azure Activity Log** view will show your updated deployment as **Published** and you will be able to verify your updated application in a web browser.
## Starting, stopping, or restarting an existing web app
To start or stop an existing Azure Web App container, (including all the deployed Java applications in it), you can use the **Azure Explorer** view.
If the **Azure Explorer** view is not already open, you can open it by clicking then **Window** menu in Eclipse, then click **Show View**, then **Other...**, then **Azure**, and then click **Azure Explorer**. If you have not previously logged in, it will prompt you to do so.
When the **Azure Explorer** view is displayed, use follow these steps to start or stop your Web App:
1. Expand the **Azure** node.
2. Expand the **Web Apps** node.
3. Right-click the desired Web App.
4. When the context menu appears, click **Start**, **Stop**, or **Restart**. Note that the menu choices are context-aware, so you can only stop a running web app or start a web app which is not currently running.
![Stopping an Existing Web App][13]
## Next steps
[!INCLUDE [azure-toolkit-additional-resources](../includes/azure-toolkit-additional-resources.md)]
For additional information about creating Azure Web Apps, see the [Web Apps Overview].
<!-- URL List -->
[Azure Toolkit for Eclipse]: azure-toolkit-for-eclipse.md
[Web Apps Overview]: /azure/app-service/app-service-web-overview
[Apache Tomcat]: http://tomcat.apache.org/
[Jetty]: http://www.eclipse.org/jetty/
<!-- IMG List -->
[01]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/01-Web-Page.png
[02]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/02-Dynamic-Web-Project.png
[03]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/03-Context-Menu.png
[04]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/04-Log-In-Dialog.png
[05]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/05-Manage-Subscriptions-Dialog.png
[06]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/06-Deploy-To-Azure-Web-Container.png
[07a]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/07a-New-Web-App-Container-Dialog.png
[07b]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/07b-New-Web-App-Container-Dialog.png
[08]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/08-New-Resource-Group-Dialog.png
[09]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/09-New-Service-Plan-Dialog.png
[10]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/10-Completed-Web-App-Container-Dialog.png
[11]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/11-Completed-Deploy-Dialog.png
[12]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/12-Activity-Log-View.png
[13]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/13-Azure-Explorer-Web-App.png
[14]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/14-publishDropdownButton.png
[15]: ./media/azure-toolkit-for-eclipse-create-hello-world-web-app/15-New-Azure-Web-Container.png

Просмотреть файл

@ -23,6 +23,11 @@ ms.author: robmcm;asirveda;martinsawicki
## Azure Toolkit for Eclipse Releases
This article contains information on the various releases and latest updates to the Azure Toolkit for Eclipse.
> [!NOTE]
> See the following web page for the latest information:
>
> <https://github.com/Microsoft/azure-tools-for-java/releases>
> [!NOTE]
> There is also an Azure Toolkit for the IntelliJ IDE. For more information, see [Azure Toolkit for IntelliJ].
>

Просмотреть файл

@ -13,7 +13,7 @@ ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: Java
ms.topic: article
ms.date: 09/11/2017
ms.date: 10/19/2017
ms.author: robmcm;asirveda
---
@ -29,8 +29,6 @@ The Azure Toolkit for Eclipse provides templates and functionality that you can
## Get started with the Azure Toolkit for Eclipse
The following articles will help you start using the Azure Toolkit for Eclipse:
* [What's new in the Azure Toolkit for Eclipse](azure-toolkit-for-eclipse-whats-new.md)
* [Installing the Azure Toolkit for Eclipse](azure-toolkit-for-eclipse-installation.md)
* [Sign-in instructions for the Azure Toolkit for Eclipse](azure-toolkit-for-eclipse-sign-in-instructions.md)
@ -59,6 +57,12 @@ The following articles demonstrate using the Azure Toolkit for Eclipse to manage
## Next steps
For more information about the Azure Toolkit for Eclipse, see the following pages:
* [Azure Toolkit Release Notes](https://github.com/Microsoft/azure-tools-for-java/releases)
* [Azure Toolkit for Eclipse in the Eclipse Marketplace](http://marketplace.eclipse.org/content/azure-toolkit-eclipse)
For more information about using Java with Azure, see the [Azure Java Developer Center](https://azure.microsoft.com/develop/java/) and the [Java Tools for Visual Studio Team Services](https://java.visualstudio.com/).
<!-- [!INCLUDE [azure-toolkit-additional-resources](../includes/azure-toolkit-additional-resources.md)] -->

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 9.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 38 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 7.3 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 17 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 6.5 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 15 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 21 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 23 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 11 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 15 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 24 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 17 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 10 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 13 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 13 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 15 KiB

Просмотреть файл

@ -24,4 +24,4 @@
- name: Azure Redis Cache
href: azure-toolkit-for-eclipse-managing-redis-caches-using-azure-explorer.md
- name: Release notes
href: azure-toolkit-for-eclipse-whats-new.md
href: https://github.com/Microsoft/azure-tools-for-java/releases

Просмотреть файл

@ -1,12 +1,12 @@
For more information about the Azure toolkits for Java IDEs, see the following links:
* [Azure Toolkit for Eclipse](/azure/azure-toolkit-for-eclipse)
* [What's new in the Azure Toolkit for Eclipse](/azure/azure-toolkit-for-eclipse-whats-new)
* [Release Notes](https://github.com/Microsoft/azure-tools-for-java/releases)
* [Installing the Azure Toolkit for Eclipse](/azure/azure-toolkit-for-eclipse-installation)
* [Create a Hello World web app for Azure in Eclipse](/azure/app-service-web/app-service-web-eclipse-create-hello-world-web-app)
* [Sign-in instructions for the Azure Toolkit for Eclipse](/azure/azure-toolkit-for-eclipse-sign-in-instructions)
* [Azure Toolkit for IntelliJ](/azure/azure-toolkit-for-intellij)
* [What's new in the Azure Toolkit for IntelliJ](/azure/azure-toolkit-for-intellij-whats-new)
* [Release Notes](https://github.com/Microsoft/azure-tools-for-java/releases)
* [Installing the Azure Toolkit for IntelliJ](/azure/azure-toolkit-for-intellij-installation)
* [Create a Hello World web app for Azure in IntelliJ](/azure/app-service-web/app-service-web-intellij-create-hello-world-web-app)
* [Sign-in instructions for the Azure Toolkit for IntelliJ](/azure/azure-toolkit-for-intellij-sign-in-instructions)

Просмотреть файл

@ -1,5 +1,5 @@
## Prerequisites
The Azure Toolkit for Eclipse requires the following software components:
To complete the steps in his article, you will need to install the Azure Toolkit for Eclipse, which requires the following software components:
* Eclipse IDE for Java EE Developers, Mars, or later. You can download it from the [Eclipse website](http://www.eclipse.org/downloads/).

Просмотреть файл

@ -4,9 +4,9 @@ If the **Azure Explorer** view is not visible in Eclipse, display it by doing th
1. Click **Window**, click **Show View**, and then click **Other**.
![Show View command](media/azure-toolkit-for-eclipse-show-azure-explorer/show-az-exp-01.png)
![Show View command](../media/azure-toolkit-for-eclipse-show-azure-explorer/show-az-exp-01.png)
2. In the **Show View** dialog box, select **Azure Explorer**, and then click **OK**.
![Show View dialog box](media/azure-toolkit-for-eclipse-show-azure-explorer/show-az-exp-02.png)
![Show View dialog box](../media/azure-toolkit-for-eclipse-show-azure-explorer/show-az-exp-02.png)

Просмотреть файл

@ -1,7 +1,7 @@
## Prerequisites
The Azure Toolkit for IntelliJ requires the following software components:
To complete the steps in his article, you will need to install the Azure Toolkit for IntelliJ, which requires the following software components:
* IntelliJ IDEA Ultimate Edition, which can be downloaded from the [JetBrains website](https://www.jetbrains.com/idea/download/).
* IntelliJ IDEA Ultimate Edition or Community Edition, which can be downloaded from the [JetBrains website](https://www.jetbrains.com/idea/download/).
* A Java Developer Kit (JDK), version 1.8 or later.

Просмотреть файл

@ -2,5 +2,5 @@
If the **Azure Explorer** tool window is not visible in IntelliJ, click **View**, then click **Tool Windows**, and then click **Azure Explorer**.
![Show Azure Explorer Tool Window](media/azure-toolkit-for-intellij-show-azure-explorer/show-az-exp-01.png)
![Show Azure Explorer Tool Window](../media/azure-toolkit-for-intellij-show-azure-explorer/show-az-exp-01.png)

Просмотреть файл

@ -0,0 +1,348 @@
---
title: Create a basic Azure web app in IntelliJ
description: This tutorial shows you how to use the Azure Toolkit for IntelliJ to create a Hello World Web App for Azure.
services: app-service
documentationcenter: java
author: selvasingh
manager: routlaw
editor: ''
ms.assetid: 75ce7b36-e3ae-491d-8305-4b42ce37db4e
ms.service: app-service
ms.workload: web
ms.tgt_pltfrm: multiple
ms.devlang: java
ms.topic: article
ms.date: 10/19/2017
ms.author: robmcm;asirveda
---
# Create a basic Azure web app in IntelliJ
This tutorial shows how to create and deploy a basic Hello World application to Azure as a web app by using the [Azure Toolkit for IntelliJ].
> [!NOTE]
>
> The Azure Toolkit for IntelliJ was updated in August 2017, with a different workflow. With that in mind, this article contains two different sections:
>
> * The first section illustrates creating a Hello World web app by using the August 2017 (or later) version of the Azure Toolkit for IntelliJ.
>
> * The second section of this article demonstrates creating a Hello World web app by using the April 2017 (or earlier) version of the toolkit.
>
[!INCLUDE [azure-toolkit-for-intellij-prerequisites](../includes/azure-toolkit-for-intellij-prerequisites.md)]
## Create a Hello World web app by using the version 3.0.7 or later toolkit
### Create a new web app project
1. Start IntelliJ and sign-in to your Azure account using the steps in the [Sign In Instructions for the Azure Toolkit for IntelliJ] article.
1. Click the **File** menu, then click **New**, and then click **Project**.
![Create New Project][file-new-project]
1. In the **New Project** dialog box, select **Maven**, then **maven-archetype-webapp**, and then click **Next**.
![Choose Maven archetype webapp][maven-archetype-webapp]
1. Specify the **GroupId** and **ArtifactId** for your web app, and then click **Next**.
![Specify GroupId and ArtifactId][groupid-and-artifactid]
1. Customize any Maven settings or accept the defaults, and then click **Next**.
![Specify Maven settings][maven-options]
1. Specify your project name and location, and then click **Finish**.
![Specify project name][project-name]
1. Within IntelliJ's Project Explorer view, expand **src**, then **main**, then **webapp**, and then double-click **index.jsp**.
![Open index page][open-index-page]
1. When your index.jsp file opens in IntelliJ, add in text to dynamically display **Hello World!** within the existing `<body>` element. Your updated `<body>` content should resemble the following example:
```java
<body><b><% out.println("Hello World!"); %></b></body>
```
![Edit index page][edit-index-page]
1. Save index.jsp.
### Deploy your web app to Azure
1. Within IntelliJ's Project Explorer view, right-click your project, choose **Azure**, and then choose **Run on Web App**.
![Run on web app menu][run-on-web-app-menu]
1. In the Run on Web App dialog box, you can choose one of the following options:
* Choose an existing web app (if one exists), and then click **Run**.
![Run on Web App dialog box][run-on-web-app-dialog]
* Click **Create New Web App**. If you choose to create a new web app, specify the requisite information for your web app, and then click **Run**.
![Create new web app][create-new-web-app-dialog]
1. The toolkit will display a status message when it has successfully deployed your web app, which will also display the URL of your deployed web app.
![Successful deployment][successfully-deployed]
1. You can browse to your web app using the link provided in the status message.
![Browsing your web app][browse-web-app]
1. After you have published your web app, your settings will be saved as the default, and you can run your application on Azure by clicking the green arrow icon on the toolbar. You can modify your settings by clicking the drop-down menu for your web app and click **Edit Configurations**.
![Edit configuration menu][edit-configuration-menu]
1. When the **Run/Debug Configurations** dialog box is displayed, you can modify any of the default settings, and then click **OK**.
![Edit configuration dialog box][edit-configuration-dialog]
<hr />
## Create a Hello World web app by using the version 3.0.6 or earlier toolkit
### Create a new web app project
1. Start IntelliJ and click the **File** menu, then click **New**, and then click **Project**.
![File New Project][02]
2. In the **New Project** dialog box, select **Java**, then **Web Application**, and then click **New** to add a Project SDK.
![New Project Dialog][03a]
3. In the Select Home Directory for JDK dialog box, select the folder where your JDK is installed, and then click **OK**. Click **Next** in the New Project dialog box to continue.
![Specify JDK Home Directory][03b]
4. For purposes of this tutorial, name the project **Java-Web-App-On-Azure**, and then click **Finish**.
![New Project Dialog][04]
5. Within IntelliJ's Project Explorer view, expand **Java-Web-App-On-Azure**, then expand **web**, and then double-click **index.jsp**.
![Open Index Page][05c]
6. When your index.jsp file opens in IntelliJ, add in text to dynamically display **Hello World!** within the existing `<body>` element. Your updated `<body>` content should resemble the following example:
```java
<body><b><% out.println("Hello World!"); %></b></body>
```
7. Save index.jsp.
### Deploy your web app to Azure
There are several ways by which you can deploy a Java web app to Azure. This tutorial describes one of the simplest: your application will be deployed to an Azure Web App Container - no special project type nor additional tools are needed. The JDK and the web container software will be provided for you by Azure, so there is no need to upload your own; all you need is your Java Web App. As a result, the publishing process for your application will take seconds, not minutes.
Before you publish your application, you first need to configure your module settings. To do so, use the following steps:
1. In IntelliJ's Project Explorer, right-click the **Java-Web-App-On-Azure** project. When the context menu appears, click **Open Module Settings**.
![Open Module Settings][05a]
2. When the Project Structure dialog box appears:
a. Click **Artifacts** in the list of **Project Settings**.
b. Change the artifact name in the **Name** box so that it doesn't contain whitespace or special characters; this is necessary since the name will be used in the Uniform Resource Identifier (URI).
c. Change the **Type** to **Web Application: Archive**.
d. Click **OK** to close the Project Structure dialog box.
![Open Module Settings][05b]
When you have configured your module settings, you can publish your application to Azure by using the following steps:
1. In IntelliJ's Project Explorer, right-click the **Java-Web-App-On-Azure** project. When the context menu appears, select **Azure**, and then click **Publish as Azure Web App...**
![Azure Publish Context Menu][06]
2. If you have not already signed in to Azure from IntelliJ, you will be prompted to sign in to your Azure account. (If you have multiple Azure accounts, some of the prompts during the sign-in process may be shown more than once, even if they appear to be the same. When this happens, continue to follow the sign-in instructions.)
![Azure Log In Dialog][07]
3. After you have successfully signed in to your Azure account, the **Manage Subscriptions** dialog box will display a list of subscriptions that are associated with your credentials. (If there are multiple subscriptions listed and you want to work with only a specific subset of them, you may optionally uncheck the subscriptions you don't want to use.) When you have selected your subscriptions, click **Close**.
![Manage Subscriptions][08]
4. When the **Deploy to Azure Web App Container** dialog box appears, it will display any Web App containers that you have previously created; if you have not created any containers, the list will be empty.
![App Containers][09]
5. If you have not created an Azure Web App Container before, or if you would like to publish your application to a new container, use the following steps. Otherwise, select an existing Web App Container and skip to step 6 below.
a. Click the **+** sign.
![Add App Container][10]
b. The **New Web App Container** dialog box will be displayed, which will be used for the next several steps.
![New App Container][11a]
c. Enter a **DNS Label** for your Web App Container; this will form the leaf DNS label of the host URL for your web application in Azure. Note that the name must be available and conform to Azure Web App naming requirements.
d. In the **Web Container** drop-down menu, select the appropriate software for your application.
Currently, you can choose from Tomcat 8, Tomcat 7 or Jetty 9. A recent distribution of the selected software will be provided by Azure, and it will run on a recent distribution of JDK 8 created by Oracle and provided by Azure.
e. In the **Subscription** drop-down menu, select the subscription you want to use for this deployment.
f. In the **Resource Group** drop-down menu, select the Resource Group with which you want to associate your Web App. (Azure Resource Groups allow you to group related resources together so that, for example, they can be deleted together.)
You can select an existing Resource Group (if you have any) and skip to step g below, or use the following steps to create a new Resource Group:
* Select **&lt;&lt; Create new Resource Group &gt;&gt;** in the **Resource Group** drop-down menu.
* The **New Resource Group** dialog box will be displayed:
![New Resource Group][12]
* In the **Name** textbox, specify a name for your new Resource Group.
* In the **Region** drop-down menu, select the appropriate Azure data center location for your Resource Group.
* Click **OK**.
g. The **App Service Plan** drop-down menu lists the app service plans that are associated with the Resource Group that you selected. (An App Service Plan specifies information such as the location of your Web App, the pricing tier and the compute instance size. A single App Service Plan can be used for multiple Web Apps, which is why it is maintained separately from a specific Web App deployment.)
You can select an existing App Service Plan (if you have any) and skip to step h below, or use the following steps to create a new App Service Plan:
* Select **&lt;&lt; Create new App Service Plan &gt;&gt;** in the **App Service Plan** drop-down menu.
* The **New App Service Plan** dialog box will be displayed:
![New App Service Plan][13]
* In the **Name** textbox, specify a name for your new App Service Plan.
* In the **Location** drop-down menu, select the appropriate Azure data center location for the plan.
* In the **Pricing Tier** drop-down menu, select the appropriate pricing for the plan. For testing purposes you can choose **Free**.
* In the **Instance Size** drop-down menu, select the appropriate instance size for the plan. For testing purposes you can choose **Small**.
* Click **OK**.
h. (Optional) By default, a recent distribution of Java 8 will be automatically deployed as your JVM by Azure to your web app container. However, you can select a different version and distribution of the JVM. To do so, use the following steps:
* Click the **JDK** tab in the **New Web App Container** dialog box.
* You can choose from one of the following options:
* Deploy the default JDK which is offered by Azure
* Deploy a 3rd party JDK from a drop-down list of additional JDKs which are available on Azure
* Deploy a custom JDK, which must be packaged as a ZIP file and either publicly available or in your Azure storage account
![New App Container JDK Tab][11b]
i. Once you have completed all of the above steps, the New Web App Container dialog box should resemble the following illustration:
![New App Container][14]
j. Click **OK** to complete the creation of your new Web App container.
Wait a few seconds for the list of the Web App containers to be refreshed, and your newly-created web app container should now be selected in the list.
6. You are now ready to complete the initial deployment of your Web App to Azure; click **OK** to deploy your Java application to the selected Web App container. By default, your application will be deployed as a subdirectory of the application server. If you want it to be deployed as the root application, check the **Deploy to root** checkbox before clicking **OK**.
![Deploy To Azure][15]
7. Next, you should see the **Azure Activity Log** view, which will indicate the deployment status of your Web App.
![Progress Indicator][16]
The process of deploying your Web App to Azure should take only a few seconds to complete. When your application is ready, you will see a link named **Published** in the **Status** column. When you click the link, it will take you to your deployed Web App's home page, or you can use the steps in the following section to browse to your web app.
### Browsing to your Web App on Azure
To browse to your Web App on Azure, you can use the **Azure Explorer** view.
If the **Azure Explorer** view is not already open, you can open it by clicking then **View** menu in IntelliJ, then click **Tool Windows**, and then click **Service Explorer**. If you have not previously logged in, it will prompt you to do so.
When the **Azure Explorer** view is displayed, follow these steps to browse to your Web App:
1. Expand the **Azure** node.
2. Expand the **Web Apps** node.
3. Right-click the desired Web App.
4. When the context menu appears, click **Open in Browser**.
![Browse Web App][17]
### Updating your web app
Updating an existing running Azure Web App is a quick and easy process, and you have two options for updating:
* You can update the deployment of an existing Java Web App.
* You can publish an additional Java application to the same Web App Container.
In either case, the process is identical and takes only a few seconds:
1. In the IntelliJ project explorer, right-click the Java application you want to update or add to an existing Web App Container.
2. When the context menu appears, select **Azure** and then **Publish as Azure Web App...**
3. Since you have already logged in previously, you will see a list of your existing Web App containers. Select the one you want to publish or re-publish your Java application to and click **OK**.
A few seconds later, the **Azure Activity Log** view will show your updated deployment as **Published** and you will be able to verify your updated application in a web browser.
### Starting, stopping, or restarting an existing web app
To start or stop an existing Azure Web App container, (including all the deployed Java applications in it), you can use the **Azure Explorer** view.
If the **Azure Explorer** view is not already open, you can open it by clicking then **View** menu in IntelliJ, then click **Tool Windows**, and then click **Service Explorer**. If you have not previously logged in, it will prompt you to do so.
When the **Azure Explorer** view is displayed, follow these steps to start or stop your Web App:
1. Expand the **Azure** node.
2. Expand the **Web Apps** node.
3. Right-click the desired Web App.
4. When the context menu appears, click **Start**, **Stop**, or **Restart**. Note that the menu choices are context-aware, so you can only stop a running web app or start a web app which is not currently running.
![Stop Web App][18]
## Next steps
[!INCLUDE [azure-toolkit-additional-resources](../includes/azure-toolkit-additional-resources.md)]
For additional information about creating Azure Web Apps, see the [Web Apps Overview].
<!-- URL List -->
[Azure Toolkit for IntelliJ]: azure-toolkit-for-intellij.md
[Web Apps Overview]: /azure/app-service/app-service-web-overview
[Apache Tomcat]: http://tomcat.apache.org/
[Jetty]: http://www.eclipse.org/jetty/
<!-- IMG List -->
[01]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/01-Web-Page.png
[02]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/02-File-New-Project.png
[03a]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/03-New-Project-Dialog.png
[03b]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/03-New-Project-SDK-Dialog.png
[04]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/04-New-Project-Dialog.png
[05a]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/05-Open-Module-Settings.png
[05b]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/05-Project-Structure-Dialog.png
[05c]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/05-Open-Index-Page.png
[06]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/06-Azure-Publish-Context-Menu.png
[07]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/07-Azure-Log-In-Dialog.png
[08]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/08-Manage-Subscriptions.png
[09]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/09-App-Containers.png
[10]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/10-Add-App-Container.png
[11a]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/11-New-App-Container.png
[11b]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/11-New-App-Container-JDK-Tab.png
[12]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/12-New-Resource-Group.png
[13]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/13-New-App-Service-Plan.png
[14]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/14-New-App-Container.png
[15]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/15-Deploy-To-Azure.png
[16]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/16-Progress-Indicator.png
[17]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/17-Browse-Web-App.png
[18]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/18-Stop-Web-App.png
[file-new-project]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/file-new-project.png
[maven-archetype-webapp]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/maven-archetype-webapp.png
[groupid-and-artifactid]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/groupid-and-artifactid.png
[maven-options]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/maven-options.png
[project-name]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/project-name.png
[open-index-page]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/open-index-page.png
[edit-index-page]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/edit-index-page.png
[run-on-web-app-menu]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/run-on-web-app-menu.png
[run-on-web-app-dialog]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/run-on-web-app-dialog.png
[create-new-web-app-dialog]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/create-new-web-app-dialog.png
[successfully-deployed]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/successfully-deployed.png
[browse-web-app]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/browse-web-app.png
[edit-configuration-menu]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/edit-configuration-menu.png
[edit-configuration-dialog]: ./media/azure-toolkit-for-intellij-create-hello-world-web-app/edit-configuration-dialog.png

Просмотреть файл

@ -13,7 +13,7 @@ ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: Java
ms.topic: article
ms.date: 09/11/2017
ms.date: 10/19/2017
ms.author: robmcm
---

Просмотреть файл

@ -13,7 +13,7 @@ ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: Java
ms.topic: article
ms.date: 09/11/2017
ms.date: 10/19/2017
ms.author: robmcm
---

Просмотреть файл

@ -13,7 +13,7 @@ ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: Java
ms.topic: article
ms.date: 09/11/2017
ms.date: 10/19/2017
ms.author: robmcm
---

Просмотреть файл

@ -13,7 +13,7 @@ ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: Java
ms.topic: article
ms.date: 09/11/2017
ms.date: 10/19/2017
ms.author: robmcm
---

Просмотреть файл

@ -13,7 +13,7 @@ ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: Java
ms.topic: article
ms.date: 09/11/2017
ms.date: 10/19/2017
ms.author: robmcm
---

Просмотреть файл

@ -13,7 +13,7 @@ ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: Java
ms.topic: article
ms.date: 09/11/2017
ms.date: 10/19/2017
ms.author: robmcm
---

Просмотреть файл

@ -13,7 +13,7 @@ ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: Java
ms.topic: article
ms.date: 09/11/2017
ms.date: 10/19/2017
ms.author: robmcm
---
@ -223,7 +223,7 @@ To learn about additional methods for creating Spring Boot apps by using Intelli
[Azure Management Portal]: http://go.microsoft.com/fwlink/?LinkID=512959
[Azure Sign In for IntelliJ]: ./azure-toolkit-for-intellij-sign-in-instructions.md
[Configuring Artifacts]: https://www.jetbrains.com/help/idea/2016.1/configuring-artifacts.html
[Deploy Spring Boot on Linux in ACS]:/azure/container-service/kubernetes/container-service-deploy-spring-boot-app-on-linux
[Deploy Spring Boot on Linux in ACS]: /azure/container-service/kubernetes/container-service-deploy-spring-boot-app-on-linux
[Docker]: https://www.docker.com/
[Publish Container with Azure Toolkit]: ./azure-toolkit-for-intellij-publish-as-docker-container.md
[Spring Boot]: http://projects.spring.io/spring-boot/

Просмотреть файл

@ -13,7 +13,7 @@ ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: Java
ms.topic: article
ms.date: 09/11/2017
ms.date: 10/19/2017
ms.author: robmcm
---

Просмотреть файл

@ -13,7 +13,7 @@ ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: Java
ms.topic: article
ms.date: 09/11/2017
ms.date: 10/19/2017
ms.author: robmcm;asirveda;martinsawicki
---
@ -23,6 +23,11 @@ ms.author: robmcm;asirveda;martinsawicki
## Azure Toolkit for IntelliJ Releases
This article contains information on the various releases and latest updates to the Azure Toolkit for IntelliJ.
> [!NOTE]
> See the following web page for the latest information:
>
> <https://github.com/Microsoft/azure-tools-for-java/releases>
> [!NOTE]
> There is also an Azure Toolkit for the Eclipse IDE. For more information, see [Azure Toolkit for Eclipse].
>

Просмотреть файл

@ -13,7 +13,7 @@ ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: Java
ms.topic: article
ms.date: 09/11/2017
ms.date: 10/19/2017
ms.author: robmcm;asirveda
---
@ -29,13 +29,11 @@ The Azure Toolkit for IntelliJ provides templates and functionality that you can
## Get started with the Azure Toolkit for IntelliJ
The following articles will help you start using the Azure Toolkit for IntelliJ:
* [What's new in the Azure Toolkit for IntelliJ](azure-toolkit-for-intellij-whats-new.md)
* [Installing the Azure Toolkit for IntelliJ](azure-toolkit-for-intellij-installation.md)
* [Sign-in instructions for the Azure Toolkit for IntelliJ](azure-toolkit-for-intellij-sign-in-instructions.md)
* [Create a Hello World web app for Azure in IntelliJ](/azure/app-service-web/app-service-web-intellij-create-hello-world-web-app)
* [Create a Hello World web app for Azure in IntelliJ](azure-toolkit-for-intellij-create-hello-world-web-app.md)
## Use the Azure Toolkit for IntelliJ with your Java Projects
The following articles demonstrate using the Azure Toolkit for IntelliJ to add Azure functionality to your Java projects:
@ -59,6 +57,12 @@ The following articles demonstrate using the Azure Toolkit for IntelliJ to manag
## Next steps
For more information about the Azure Toolkit for IntelliJ, see the following pages:
* [Azure Toolkit Release Notes](https://github.com/Microsoft/azure-tools-for-java/releases)
* [Azure Toolkit for IntelliJ in the JetBrains Plugins Repository](https://plugins.jetbrains.com/plugin/8053-azure-toolkit-for-intellij)
For more information about using Java with Azure, see the [Azure Java Developer Center](https://azure.microsoft.com/develop/java/) and the [Java Tools for Visual Studio Team Services](https://java.visualstudio.com/).
<!-- [!INCLUDE [azure-toolkit-additional-resources](../includes/azure-toolkit-additional-resources.md)] -->

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 9.4 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 46 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 47 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 53 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 12 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 44 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 62 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 32 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 58 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 15 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 8.2 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 9.0 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 10 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 18 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 16 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 9.5 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 7.6 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 20 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 11 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 7.7 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 48 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 48 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 14 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 39 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 28 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 35 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 26 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 24 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 9.5 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 58 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 22 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 22 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 9.2 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 25 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 52 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 47 KiB

Просмотреть файл

@ -4,7 +4,7 @@
- name: Install
href: azure-toolkit-for-intellij-installation.md
- name: Get Started
href: /azure/app-service-web/app-service-web-intellij-create-hello-world-web-app
href: azure-toolkit-for-intellij-create-hello-world-web-app.md
maintainContext: true
- name: Tutorials
items:
@ -27,4 +27,5 @@
- name: Azure Redis Cache
href: azure-toolkit-for-intellij-managing-redis-caches-using-azure-explorer.md
- name: Release notes
href: azure-toolkit-for-intellij-whats-new.md
href: https://github.com/Microsoft/azure-tools-for-java/releases

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 35 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 8.6 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 48 KiB

Просмотреть файл

@ -0,0 +1,226 @@
---
title: How to configure a Spring Boot Initializer app to use Redis Cache
description: Learn how to configure a Spring Boot application created with the Spring Initializr to use Azure Redis Cache.
services: redis-cache
documentationcenter: java
author: rmcmurray
manager: routlaw
editor: ''
keywords: Spring, Spring Boot, Spring Framework, Spring Starter, Redis Cache
ms.assetid:
ms.service: cache
ms.workload: na
ms.tgt_pltfrm: cache-redis
ms.devlang: java
ms.topic: article
ms.date: 10/11/2017
ms.author: robmcm;zhijzhao;yidon
---
# How to configure a Spring Boot Initializer app to use Redis Cache
## Overview
The **[Spring Framework]** is an open-source solution that helps Java developers create enterprise-level applications. One of the more-popular projects that is built on top of that platform is [Spring Boot], which provides a simplified approach for creating stand-alone Java applications. To help developers get started with Spring Boot, several sample Spring Boot packages are available at <https://github.com/spring-guides/>. In addition to choosing from the list of basic Spring Boot projects, the **[Spring Initializr]** helps developers get started with creating custom Spring Boot applications.
This article walks you through creating a Redis cache using the Azure portal, then using the **Spring Initializr** to create a custom application, and then creating a Java web application that stores and retrieves data using your Redis cache.
## Prerequisites
The following prerequisites are required in order to follow the steps in this article:
* An Azure subscription; if you don't already have an Azure subscription, you can activate your [MSDN subscriber benefits] or sign up for a [free Azure account].
* A [Java Development Kit (JDK)](http://www.oracle.com/technetwork/java/javase/downloads/), version 1.7 or later.
* [Apache Maven](http://maven.apache.org/), version 3.0 or later.
## Create a Redis cache on Azure
1. Browse to the Azure portal at <https://portal.azure.com/> and click the item for **+New**.
![Azure portal][AZ01]
1. Click **Database**, and then click **Redis Cache**.
![Azure portal][AZ02]
1. On the **New Redis Cache** page, specify the following information:
* Enter the **DNS name** for your cache.
* Specify your **Subscription**, **Resource group**, **Location**, and **Pricing tier**.
* For this tutorial, choose **Unblock port 6379**.
> [!NOTE]
>
> You can use SSL with Redis caches, but you would need to use a different Redis client like Jedis. For more information, see [How to use Azure Redis Cache with Java][Redis Cache with Java].
>
When you have specified these options, click **Create** to create your cache.
![Azure portal][AZ03]
1. Once your cache has been completed, you will see it listed on your Azure **Dashboard**, as well as under the **All Resources**, and **Redis Caches** pages. You can click on your cache on any of those locations to open the properties page for your cache.
![Azure portal][AZ04]
1. When the page that contains the list of properties for your cache is displayed, click **Access keys** and copy your access keys for your cache.
![Azure portal][AZ05]
## Create a custom application using the Spring Initializr
1. Browse to <https://start.spring.io/>.
1. Specify that you want to generate a **Maven** project with **Java**, enter the **Group** and **Aritifact** names for your application, and then click the link to **Switch to the full version** of the Spring Initializr.
![Basic Spring Initializr options][SI01]
> [!NOTE]
>
> The Spring Initializr will use the **Group** and **Aritifact** names to create the package name; for example: *com.contoso.myazuredemo*.
>
1. Scroll down to the **Web** section and check the box for **Web**, then scroll down to the **NoSQL** section and check the box for **Redis**, then scroll to the bottom of the page and click the button to **Generate Project**.
![Full Spring Initializr options][SI02]
1. When prompted, download the project to a path on your local computer.
![Download custom Spring Boot project][SI03]
1. After you have extracted the files on your local system, your custom Spring Boot application will be ready for editing.
![Custom Spring Boot project files][SI04]
## Configure your custom Spring Boot to use your Redis Cache
1. Locate the *application.properties* file in the *resources* directory of your app, or create the file if it does not already exist.
![Locate the application.properties file][RE01]
1. Open the *application.properties* file in a text editor, and add the following lines to the file, and replace the sample values with the appropriate properties from your cache:
```yaml
# Specify the DNS URI of your Redis cache.
spring.redis.host=myspringbootcache.redis.cache.windows.net
# Specify the port for your Redis cache.
spring.redis.port=6379
# Specify the access key for your Redis cache.
spring.redis.password=57686f6120447564652c2049495320526f636b73=
```
![Editing the application.properties file][RE02]
> [!NOTE]
>
> If you were using a different Redis client like Jedis that enables SSL, you would specify port 6380 in your *application.properties* file. For more information, see [How to use Azure Redis Cache with Java][Redis Cache with Java].
>
1. Save and close the *application.properties* file.
1. Create a folder named *controller* under the source folder for your package; for example:
`C:\SpringBoot\myazuredemo\src\main\java\com\contoso\myazuredemo\controller`
-or-
`/users/example/home/myazuredemo/src/main/java/com/contoso/myazuredemo/controller`
1. Create a new file named *HelloController.java* in the *controller* folder. Open the file in a text editor and add the following code to it:
```java
package com.contoso.myazuredemo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
@RestController
public class HelloController {
@Autowired
private StringRedisTemplate template;
@RequestMapping("/")
// Define the Hello World controller.
public String hello() {
ValueOperations<String, String> ops = this.template.opsForValue();
// Add a Hello World string to your cache.
String key = "greeting";
if (!this.template.hasKey(key)) {
ops.set(key, "Hello World!");
}
// Return the string from your cache.
return ops.get(key);
}
}
```
Where you will need to replace `com.contoso.myazuredemo` with the package name for your project.
1. Save and close the *HelloController.java* file.
1. Build your Spring Boot application with Maven and run it; for example:
```shell
mvn clean package
mvn spring-boot:run
```
1. Test the web app by browsing to http://localhost:8080 using a web browser, or use the syntax like the following example if you have curl available:
```shell
curl http://localhost:8080
```
You should see the "Hello World!" message from your sample controller displayed, which is being retrieved dynamically from your Redis cache.
## Next steps
For more information about using Spring Boot applications on Azure, see the following articles:
* [Deploy a Spring Boot Application to the Azure App Service](deploy-spring-boot-java-web-app-on-azure.md)
* [Running a Spring Boot Application on a Kubernetes Cluster in the Azure Container Service](deploy-spring-boot-java-app-on-kubernetes.md)
For more information about using Azure with Java, see the [Azure Java Developer Center] and the [Java Tools for Visual Studio Team Services].
For more information about getting started using Redis Cache with Java on Azure, see [How to use Azure Redis Cache with Java][Redis Cache with Java].
<!-- URL List -->
[Azure Java Developer Center]: https://azure.microsoft.com/develop/java/
[free Azure account]: https://azure.microsoft.com/pricing/free-trial/
[Java Tools for Visual Studio Team Services]: https://java.visualstudio.com/
[MSDN subscriber benefits]: https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/
[Spring Boot]: http://projects.spring.io/spring-boot/
[Spring Initializr]: https://start.spring.io/
[Spring Framework]: https://spring.io/
[Redis Cache with Java]: /azure/redis-cache/cache-java-get-started
<!-- IMG List -->
[AZ01]: ./media/configure-spring-boot-initializer-java-app-with-redis-cache/AZ01.png
[AZ02]: ./media/configure-spring-boot-initializer-java-app-with-redis-cache/AZ02.png
[AZ03]: ./media/configure-spring-boot-initializer-java-app-with-redis-cache/AZ03.png
[AZ04]: ./media/configure-spring-boot-initializer-java-app-with-redis-cache/AZ04.png
[AZ05]: ./media/configure-spring-boot-initializer-java-app-with-redis-cache/AZ05.png
[SI01]: ./media/configure-spring-boot-initializer-java-app-with-redis-cache/SI01.png
[SI02]: ./media/configure-spring-boot-initializer-java-app-with-redis-cache/SI02.png
[SI03]: ./media/configure-spring-boot-initializer-java-app-with-redis-cache/SI03.png
[SI04]: ./media/configure-spring-boot-initializer-java-app-with-redis-cache/SI04.png
[RE01]: ./media/configure-spring-boot-initializer-java-app-with-redis-cache/RE01.png
[RE02]: ./media/configure-spring-boot-initializer-java-app-with-redis-cache/RE02.png

Просмотреть файл

@ -0,0 +1,344 @@
---
title: How to use the Spring Boot Starter with an Azure Cosmos DB DocumentDB API
description: Learn how to configure an application created with the Spring Boot Initializer with the Azure Cosmos DB DocumentDB API.
services: cosmos-db
documentationcenter: java
author: rmcmurray
manager: routlaw
editor: ''
keywords: Spring, Spring Boot, Spring Framework, Spring Starter, Cosmos DB, DocumentDB
ms.assetid:
ms.service: cosmos-db
ms.workload: data-services
ms.tgt_pltfrm: multiple
ms.devlang: java
ms.topic: article
ms.date: 10/11/2017
ms.author: robmcm;yungez;kevinzha
---
# How to use the Spring Boot Starter with Azure Cosmos DB DocumentDB API
## Overview
The **[Spring Framework]** is an open-source solution that helps Java developers create enterprise-level applications. One of the more-popular projects that is built on top of that platform is [Spring Boot], which provides a simplified approach for creating stand-alone Java applications. To help developers get started with Spring Boot, several sample Spring Boot packages are available at <https://github.com/spring-guides/>. In addition to choosing from the list of basic Spring Boot projects, the **[Spring Initializr]** helps developers get started with creating custom Spring Boot applications.
Azure Cosmos DB is a globally-distributed database service that allows developers to work with data using a variety of standard APIs, such as DocumentDB, MongoDB, Graph, and Table APIs. Microsoft's Spring Boot Starter enables developers to use Spring Boot applications that easily integrate with Azure Cosmos DB by using DocumentDB APIs.
This article demonstrates creating an Azure Cosmos DB using the Azure portal, then using the **Spring Initializr** to create a custom java application, and then add the Spring Boot Starter functionality to your custom application to store data in and retrieve data from your Azure Cosmos DB by using the DocumentDB API.
## Prerequisites
The following prerequisites are required in order to follow the steps in this article:
* An Azure subscription; if you don't already have an Azure subscription, you can activate your [MSDN subscriber benefits] or sign up for a [free Azure account].
* A [Java Development Kit (JDK)](http://www.oracle.com/technetwork/java/javase/downloads/), version 1.7 or later.
* [Apache Maven](http://maven.apache.org/), version 3.0 or later.
## Create an Azure Cosmos DB by using the Azure portal
1. Browse to the Azure portal at <https://portal.azure.com/> and click **+New**.
![Azure portal][AZ01]
1. Click **Databases**, and then click **Azure Cosmos DB**.
![Azure portal][AZ02]
1. On the **Azure Cosmos DB** page, enter the following information:
* Enter a unique **ID**, which you will use as the URI for your database. For example: *wingtiptoysdata.documents.azure.com*.
* Choose **SQL (Document DB)** for the API.
* Choose the **Subscription** you want to use for your database.
* Specify whether to create a new **Resource group** for your database, or choose an existing resource group.
* Specify the **Location** for your database.
When you have specified these options, click **Create** to create your database.
![Azure portal][AZ03]
1. When your database has been created, it is listed on your Azure **Dashboard**, as well as under the **All Resources** and **Azure Cosmos DB** pages. You can click on your database on any of those locations to open the properties page for your cache.
![Azure portal][AZ04]
1. When the properties page for your database is displayed, click **Access keys** and copy your URI and access keys for your database; you will use these values in your Spring Boot application.
![Azure portal][AZ05]
## Create a simple Spring Boot application with the Spring Initializr
1. Browse to <https://start.spring.io/>.
1. Specify that you want to generate a **Maven** project with **Java**, enter the **Group** and **Artifact** names for your application, and then click the button to **Generate Project**.
![Basic Spring Initializr options][SI01]
> [!NOTE]
>
> The Spring Initializr uses the **Group** and **Artifact** names to create the package name; for example: *com.example.wintiptoys*.
>
1. When prompted, download the project to a path on your local computer.
![Download custom Spring Boot project][SI02]
1. After you have extracted the files on your local system, your simple Spring Boot application will be ready for editing.
![Custom Spring Boot project files][SI03]
## Configure your Spring Boot app to use the Azure Spring Boot Starter
1. Locate the *pom.xml* file in the directory of your app; for example:
`C:\SpringBoot\wingtiptoys\pom.xml`
-or-
`/users/example/home/wingtiptoys/pom.xml`
![Locate the pom.xml file][PM01]
1. Open the *pom.xml* file in a text editor, and add the following lines to list of `<dependencies>`:
```xml
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-documentdb-spring-boot-starter</artifactId>
<version>0.1.4</version>
</dependency>
```
![Editing the pom.xml file][PM02]
1. Save and close the *pom.xml* file.
## Configure your Spring Boot app to use your Azure Cosmos DB
1. Locate the *application.properties* file in the *resources* directory of your app; for example:
`C:\SpringBoot\wingtiptoys\src\main\resources\application.properties`
-or-
`/users/example/home/wingtiptoys/src/main/resources/application.properties`
![Locate the application.properties file][RE01]
1. Open the *application.properties* file in a text editor, and add the following lines to the file, and replace the sample values with the appropriate properties for your database:
```yaml
# Specify the DNS URI of your Azure Cosmos DB.
azure.documentdb.uri=https://wingtiptoys.documents.azure.com:443/
# Specify the access key for your database.
azure.documentdb.key=57686f6120447564652c20426f6220526f636b73==
# Specify the name of your database.
azure.documentdb.database=wingtiptoysdata
```
![Editing the application.properties file][RE02]
1. Save and close the *application.properties* file.
## Add sample code to implement basic database functionality
In this section you create two Java classes for storing user data, and then you modify your main application class to create an instance of the user class and save it to your database.
### Define a basic class for storing user data
1. Create a new file named *User.java* in the same directory as your main application Java file.
1. Open the *User.java* file in a text editor, and add the following lines to the file to define a generic user class that stores and retrieve values in your database:
```java
package com.example.wingtiptoys;
public class User {
private String id;
private String firstName;
private String lastName;
public User(String id, String firstName, String lastName) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
}
public String getId() {
return this.id;
}
public void setId(String id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Override
public String toString() {
return String.format("User: %s %s", firstName, lastName);
}
}
```
1. Save and close the *User.java* file.
### Define a data repository interface
1. Create a new file named *UserRepository.java* in the same directory as your main application Java file.
1. Open the *UserRepository.java* file in a text editor, and add the following lines to the file to define a user repository interface that extends the default DocumentDB repository interface:
```java
package com.example.wingtiptoys;
import com.microsoft.azure.spring.data.documentdb.repository.DocumentDbRepository;
import org.springframework.stereotype.Repository;
@Repository
public interface UserRepository extends DocumentDbRepository<User, String> {}
```
1. Save and close the *UserRepository.java* file.
### Modify the main application class
1. Locate the main application Java file in the package directory of your app; for example:
`C:\SpringBoot\wingtiptoys\src\main\java\com\example\wingtiptoys\WingtiptoysApplication.java`
-or-
`/users/example/home/wingtiptoys/src/main/java/com/example/wingtiptoys/WingtiptoysApplication.java`
![Locate the application Java file][JV01]
1. Open the main application Java file in a text editor, and add the following lines to the file:
```java
package com.example.wingtiptoys;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
@SpringBootApplication
public class WingtiptoysApplication implements CommandLineRunner {
@Autowired
private UserRepository repository;
public static void main(String[] args) {
SpringApplication.run(WingtiptoysApplication.class, args);
}
public void run(String... var1) throws Exception {
final User testUser = new User("testId", "testFirstName", "testLastName");
repository.deleteAll();
repository.save(testUser);
final User result = repository.findOne(testUser.getId());
System.out.printf("\n\n%s\n\n",result.toString());
}
}
```
1. Save and close the main application Java file.
## Build and test your app
1. Open a command prompt and change directory to the folder where your *pom.xml* file is located; for example:
`cd C:\SpringBoot\wingtiptoys`
-or-
`cd /users/example/home/wingtiptoys`
1. Build your Spring Boot application with Maven and run it; for example:
```shell
mvn package
java -jar target/wingtiptoys-0.0.1-SNAPSHOT.jar
```
1. Your application will display several runtime messages, and you should see the message `User: testFirstName testLastName` displayed to indicate that values have been successfully stored and retrieved from your database.
![Successful output from the application][JV02]
1. OPTIONAL: You can use the Azure portal to view the contents of your Azure Cosmos DB from the properties page for your database by clicking **Document Explorer**, and then selecting and item from the displayed list to view the contents.
![Using the Document Explorer to view your data][JV03]
## Next steps
For more information about using Azure Cosmos DB and Java, see the following articles:
* [Azure Cosmos DB Documentation].
* [Azure Cosmos DB: Build a DocumentDB API app with Java and the Azure portal][Build a DocumentDB API app with Java]
For more information about using Spring Boot applications on Azure, see the following articles:
* [Spring Boot DocumenDB Starter for Azure](https://github.com/Microsoft/azure-spring-boot-starters/tree/master/azure-documentdb-spring-boot-starter-sample)
* [Deploy a Spring Boot Application to the Azure App Service](deploy-spring-boot-java-web-app-on-azure.md)
* [Running a Spring Boot Application on a Kubernetes Cluster in the Azure Container Service](deploy-spring-boot-java-app-on-kubernetes.md)
For more information about using Azure with Java, see the [Azure Java Developer Center] and the [Java Tools for Visual Studio Team Services].
<!-- URL List -->
[Azure Cosmos DB Documentation]: /azure/cosmos-db/
[Azure Java Developer Center]: https://azure.microsoft.com/develop/java/
[Build a DocumentDB API app with Java]: https://docs.microsoft.com/azure/cosmos-db/create-documentdb-java
[free Azure account]: https://azure.microsoft.com/pricing/free-trial/
[Java Tools for Visual Studio Team Services]: https://java.visualstudio.com/
[MSDN subscriber benefits]: https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/
[Spring Boot]: http://projects.spring.io/spring-boot/
[Spring Initializr]: https://start.spring.io/
[Spring Framework]: https://spring.io/
<!-- IMG List -->
[AZ01]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/AZ01.png
[AZ02]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/AZ02.png
[AZ03]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/AZ03.png
[AZ04]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/AZ04.png
[AZ05]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/AZ05.png
[SI01]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/SI01.png
[SI02]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/SI02.png
[SI03]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/SI03.png
[RE01]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/RE01.png
[RE02]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/RE02.png
[PM01]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/PM01.png
[PM02]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/PM02.png
[JV01]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/JV01.png
[JV02]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/JV02.png
[JV03]: ./media/configure-spring-boot-starter-java-app-with-cosmos-db/JV03.png

Просмотреть файл

@ -0,0 +1,337 @@
---
title: How to use the Maven Plugin for Azure Web Apps to deploy a containerized Spring Boot app to Azure
description: Learn how to use the Maven Plugin for Azure Web Apps to deploy a Spring Boot app to Azure.
services: app-service
documentationcenter: java
author: rmcmurray
manager: routlaw
editor: ''
keywords: Spring, Spring Boot, Spring Framework, Maven
ms.assetid:
ms.service: app-service
ms.workload: web
ms.tgt_pltfrm: multiple
ms.devlang: java
ms.topic: article
ms.date: 10/11/2017
ms.author: robmcm;kevinzha
---
# How to use the Maven Plugin for Azure Web Apps to deploy a containerized Spring Boot app to Azure
The [Maven Plugin for Azure Web Apps](https://github.com/Microsoft/azure-maven-plugins/tree/master/azure-webapp-maven-plugin) for [Apache Maven](http://maven.apache.org/) provides seamless integration of Azure App Service into Maven projects, and streamlines the process for developers to deploy web apps to Azure App Service .
This article demonstrates using the Maven Plugin for Azure Web Apps to deploy a sample Spring Boot application in a Docker container to Azure App Services.
> [!NOTE]
>
> The Maven Plugin for Azure Web Apps is currently available as a preview. For now, only FTP publishing is supported, although additional features are planned for the future.
>
## Prerequisites
In order to complete the steps in this tutorial, you need to have the following prerequisites:
* An Azure subscription; if you don't already have an Azure subscription, you can activate your [MSDN subscriber benefits] or sign up for a [free Azure account].
* The [Azure Command-Line Interface (CLI)].
* An up-to-date [Java Development Kit (JDK)], version 1.7 or later.
* Apache's [Maven] build tool (Version 3).
* A [Git] client.
* A [Docker] client.
> [!NOTE]
>
> Due to the virtualization requirements of this tutorial, you cannot follow the steps in this article on a virtual machine; you must use a physical computer with virtualization features enabled.
>
## Clone the sample Spring Boot on Docker web app
In this section, you clone a containerized Spring Boot application and test it locally.
1. Open a command prompt or terminal window and create a local directory to hold your Spring Boot application, and change to that directory; for example:
```shell
md C:\SpringBoot
cd C:\SpringBoot
```
-- or --
```shell
md /users/robert/SpringBoot
cd /users/robert/SpringBoot
```
1. Clone the [Spring Boot on Docker Getting Started] sample project into the directory you created; for example:
```shell
git clone https://github.com/microsoft/gs-spring-boot-docker
```
1. Change directory to the completed project; for example:
```shell
cd gs-spring-boot-docker/complete
```
1. Build the JAR file using Maven; for example:
```shell
mvn clean package
```
1. When the web app has been created, start the web app using Maven; for example:
```shell
mvn spring-boot:run
```
1. Test the web app by browsing to it locally using a web browser. For example, you could use the following command if you have curl available:
```shell
curl http://localhost:8080
```
1. You should see the following message displayed: **Hello Docker World**
## Create an Azure service principal
In this section, you create an Azure service principal that the Maven plugin uses when deploying your container to Azure.
1. Open a command prompt.
1. Sign into your Azure account by using the Azure CLI:
```shell
az login
```
Follow the instructions to complete the sign-in process.
1. Create an Azure service principal:
```shell
az ad sp create-for-rbac --name "uuuuuuuu" --password "pppppppp"
```
Where `uuuuuuuu` is the user name and `pppppppp` is the password for the service principal.
1. Azure responds with JSON that resembles the following example:
```json
{
"appId": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"displayName": "uuuuuuuu",
"name": "http://uuuuuuuu",
"password": "pppppppp",
"tenant": "tttttttt-tttt-tttt-tttt-tttttttttttt"
}
```
> [!NOTE]
>
> You will use the values from this JSON response when you configure the Maven plugin to deploy your container to Azure. The `aaaaaaaa`, `uuuuuuuu`, `pppppppp`, and `tttttttt` are placeholder values, which are used in this example to make it easier to map these values to their respective elements when you configure your Maven `settings.xml` file in the next section.
>
>
## Configure Maven to use your Azure service principal
In this section, you use the values from your Azure service principal to configure the authentication that Maven will use when deploying your container to Azure.
1. Open your Maven `settings.xml` file in a text editor; this file might be in a path like the following examples:
* `/etc/maven/settings.xml`
* `%ProgramFiles%\apache-maven\3.5.0\conf\settings.xml`
* `$HOME/.m2/settings.xml`
1. Add your Azure service principal settings from the previous section of this tutorial to the `<servers>` collection in the *settings.xml* file; for example:
```xml
<servers>
<server>
<id>azure-auth</id>
<configuration>
<client>aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa</client>
<tenant>tttttttt-tttt-tttt-tttt-tttttttttttt</tenant>
<key>pppppppp</key>
<environment>AZURE</environment>
</configuration>
</server>
</servers>
```
Where:
Element | Description
---|---|---
`<id>` | Specifies a unique name which Maven uses to look up your security settings when you deploy your web app to Azure.
`<client>` | Contains the `appId` value from your service principal.
`<tenant>` | Contains the `tenant` value from your service principal.
`<key>` | Contains the `password` value from your service principal.
`<environment>` | Defines the target Azure cloud environment, which is `AZURE` in this example. (A full list of environments is available in the [Maven Plugin for Azure Web Apps] documentation)
1. Save and close the *settings.xml* file.
## OPTIONAL: Deploy your local Docker file to Docker Hub
If you have a Docker account, you can build your Docker container image locally and push it to Docker Hub. To do so, use the following steps.
1. Open the `pom.xml` file for your Spring Boot application in a text editor.
1. Locate the `<imageName>` child element of the `<containerSettings>` element.
1. Update the `${docker.image.prefix}` value with your Docker account name:
```xml
<containerSettings>
<imageName>mydockeraccountname/${project.artifactId}</imageName>
</containerSettings>
```
1. Choose one of the following deployment methods:
* Build your container image locally with Maven, and then use Docker to push your container to Docker Hub:
```shell
mvn clean package docker:build
docker push
```
* If you have the [Docker plugin for Maven] installed, you can automatically build and your container image to Docker Hub by using the `-DpushImage` parameter:
```shell
mvn clean package docker:build -DpushImage
```
## OPTIONAL: Customize your pom.xml before deploying your container to Azure
Open the `pom.xml` file for your Spring Boot application in a text editor, and then locate the `<plugin>` element for `azure-webapp-maven-plugin`. This element should resemble the following example:
```xml
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>0.1.3</version>
<configuration>
<authentication>
<serverId>azure-auth</serverId>
</authentication>
<resourceGroup>maven-plugin</resourceGroup>
<appName>maven-linux-app-${maven.build.timestamp}</appName>
<region>westus</region>
<containerSettings>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
</containerSettings>
<appSettings>
<property>
<name>PORT</name>
<value>8080</value>
</property>
</appSettings>
</configuration>
</plugin>
```
There are several values that you can modify for the Maven plugin, and a detailed description for each of these elements is available in the [Maven Plugin for Azure Web Apps] documentation. That being said, there are several values that are worth highlighting in this article:
Element | Description
---|---|---
`<version>` | Specifies the version of the [Maven Plugin for Azure Web Apps]. You should check the version listed in the [Maven Central Respository](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22azure-webapp-maven-plugin%22) to ensure that you are using the latest version.
`<authentication>` | Specifies the authentication information for Azure, which in this example contains a `<serverId>` element that contains `azure-auth`; Maven uses that value to look up the Azure service principal values in your Maven *settings.xml* file, which you defined in an earlier section of this article.
`<resourceGroup>` | Specifies the target resource group, which is `maven-plugin` in this example. The resource group will be created during deployment if it does not already exist.
`<appName>` | Specifies the target name for your web app. In this example, the target name is `maven-linux-app-${maven.build.timestamp}`, where the `${maven.build.timestamp}` suffix is appended in this example to avoid conflict. (The timestamp is optional; you can specify any unique string for the app name.)
`<region>` | Specifies the target region, which in this example is `westus`. (A full list is in the [Maven Plugin for Azure Web Apps] documentation.)
`<appSettings>` | Specifies any unique settings for Maven to use when deploying your web app to Azure. In this example, a `<property>` element contains a name/value pair of child elements that specify the port for your app.
> [!NOTE]
>
> The settings to change the port number in this example are only necessary when you are changing the port from the default.
>
## Build and deploy your container to Azure
Once you have configured all of the settings in the preceding sections of this article, you are ready to deploy your container to Azure. To do so, use the following steps:
1. From the command prompt or terminal window that you were using earlier, rebuild the JAR file using Maven if you made any changes to the *pom.xml* file; for example:
```shell
mvn clean package
```
1. Deploy your web app to Azure by using Maven; for example:
```shell
mvn azure-webapp:deploy
```
Maven will deploy your web app to Azure; if the web app does not already exist, it will be created.
> [!NOTE]
>
> If the region which you specify in the `<region>` element of your *pom.xml* file does not have enough servers available when you start your deployment, you might see an error similar to the following example:
>
> ```
> [INFO] Start deploying to Web App maven-linux-app-20170804...
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time: 31.059 s
> [INFO] Finished at: 2017-08-04T12:15:47-07:00
> [INFO] Final Memory: 51M/279M
> [INFO] ------------------------------------------------------------------------
> [ERROR] Failed to execute goal com.microsoft.azure:azure-webapp-maven-plugin:0.1.3:deploy (default-cli) on project gs-spring-boot-docker: null: MojoExecutionException: CloudException: OnError while emitting onNext value: retrofit2.Response.class
> ```
>
> If this happens, you can specify another region and re-run the Maven command to deploy your application.
>
>
When your web has been deployed, you will be able to manage it by using the [Azure portal].
* Your web app will be listed in **App Services**:
![Web app listed in Azure portal App Services][AP01]
* And the URL for your web app will be listed in the **Overview** for your web app:
![Determining the URL for your web app][AP02]
<!--
## OPTIONAL: Configure the embedded Tomcat server to run on a different port
The embedded Tomcat server in the sample Spring Boot application is configured to run on port 8080 by default. However, if you want to run the embedded Tomcat server to run on a different port, such as port 80 for local testing, you can configure the port by using the following steps.
1. Go to the *resources* directory (or create the directory if it does not exist); for example:
```shell
cd src/main/resources
```
1. Open the *application.yml* file in a text editor if it exists, or create a new YAML file if it does not exist.
1. Modify the **server** setting so that the server runs on port 80; for example:
```yaml
server:
port: 80
```
1. Save and close the *application.yml* file.
-->
## Next steps
For more information about the various technologies discussed in this article, see the following articles:
* [Maven Plugin for Azure Web Apps]
* [Log in to Azure from the Azure CLI](/azure/xplat-cli-connect)
* [How to use the Maven Plugin for Azure Web Apps to deploy a Spring Boot app to Azure App Service ](deploy-spring-boot-java-app-with-maven-plugin.md)
* [Create an Azure service principal with Azure CLI 2.0](/cli/azure/create-an-azure-service-principal-azure-cli)
* [Maven Settings Reference](https://maven.apache.org/settings.html)
* [Docker plugin for Maven]
<!-- URL List -->
[Azure Command-Line Interface (CLI)]: /cli/azure/overview
[Azure Java Developer Center]: https://azure.microsoft.com/develop/java/
[Azure portal]: https://portal.azure.com/
[Docker]: https://www.docker.com/
[Docker plugin for Maven]: https://github.com/spotify/docker-maven-plugin
[free Azure account]: https://azure.microsoft.com/pricing/free-trial/
[Git]: https://github.com/
[Java Developer Kit (JDK)]: http://www.oracle.com/technetwork/java/javase/downloads/
[Java Tools for Visual Studio Team Services]: https://java.visualstudio.com/
[Maven]: http://maven.apache.org/
[MSDN subscriber benefits]: https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/
[Spring Boot]: http://projects.spring.io/spring-boot/
[Spring Boot on Docker Getting Started]: https://github.com/spring-guides/gs-spring-boot-docker
[Spring Framework]: https://spring.io/
[Maven Plugin for Azure Web Apps]: https://github.com/Microsoft/azure-maven-plugins/tree/master/azure-webapp-maven-plugin
<!-- IMG List -->
[AP01]: ./media/deploy-containerized-spring-boot-java-app-with-maven-plugin/AP01.png
[AP02]: ./media/deploy-containerized-spring-boot-java-app-with-maven-plugin/AP02.png

Просмотреть файл

@ -0,0 +1,406 @@
---
title: How to use the Maven Plugin for Azure Web Apps to deploy a Spring Boot app in Azure Container Registry to Azure App Service
description: This tutorial will walk you though the steps to deploy a Spring Boot application in Azure Container Registry to Azure to Azure App Service by using a Maven plugin.
services: container-registry
documentationcenter: java
author: rmcmurray
manager: routlaw
editor: ''
keywords: Spring, Spring Boot, Spring Framework, Maven
ms.assetid:
ms.service: multiple
ms.workload: web
ms.tgt_pltfrm: multiple
ms.devlang: java
ms.topic: article
ms.date: 10/11/2017
ms.author: robmcm;kevinzha
---
# How to use the Maven Plugin for Azure Web Apps to deploy a Spring Boot app in Azure Container Registry to Azure App Service
The **[Spring Framework]** is a popular open-source framework that helps Java developers create web, mobile, and API applications. This tutorial uses a sample app created using [Spring Boot], a convention-driven approach for using Spring to get started quickly.
This article demonstrates how to deploy a sample Spring Boot application to Azure Container Registry, and then use the Maven Plugin for Azure Web Apps to deploy your application to Azure App Service.
> [!NOTE]
>
> The Maven Plugin for Azure Web Apps is currently available as a preview. For now, only FTP publishing is supported, although additional features are planned for the future.
>
## Prerequisites
In order to complete the steps in this tutorial, you need to have the following prerequisites:
* An Azure subscription; if you don't already have an Azure subscription, you can activate your [MSDN subscriber benefits] or sign up for a [free Azure account].
* The [Azure Command-Line Interface (CLI)].
* An up-to-date [Java Development Kit (JDK)], version 1.7 or later.
* Apache's [Maven] build tool (Version 3).
* A [Git] client.
* A [Docker] client.
> [!NOTE]
>
> Due to the virtualization requirements of this tutorial, you cannot follow the steps in this article on a virtual machine; you must use a physical computer with virtualization features enabled.
>
## Clone the sample Spring Boot on Docker web app
In this section, you clone a containerized Spring Boot application and test it locally.
1. Open a command prompt or terminal window and create a local directory to hold your Spring Boot application, and change to that directory; for example:
```shell
md C:\SpringBoot
cd C:\SpringBoot
```
-- or --
```shell
md /users/robert/SpringBoot
cd /users/robert/SpringBoot
```
1. Clone the [Spring Boot on Docker Getting Started] sample project into the directory you created; for example:
```shell
git clone -b private-registry https://github.com/Microsoft/gs-spring-boot-docker
```
1. Change directory to the completed project; for example:
```shell
cd gs-spring-boot-docker/complete
```
1. Build the JAR file using Maven; for example:
```shell
mvn clean package
```
1. When the web app has been created, start the web app using Maven; for example:
```shell
mvn spring-boot:run
```
1. Test the web app by browsing to it locally using a web browser. For example, you could use the following command if you have curl available:
```shell
curl http://localhost:8080
```
1. You should see the following message displayed: **Hello Docker World**
![Browse Sample App Locally][SB01]
> [!NOTE]
>
> When you are using Docker locally, you may see an error which states that you cannot connect to localhost on port 2375. If this happens, you may need to enable using Docker locally without TLS. To do so, open your Docker settings and check the option to **Expose Docker Daemon on TCP://localhost:2375 without TLS**.
>
> ![Expose Docker daemon on local TCP port 2375][TL01]
## Create an Azure service principal
In this section, you create an Azure service principal that the Maven plugin uses when deploying your container to Azure.
1. Open a command prompt.
1. Sign into your Azure account by using the Azure CLI:
```azurecli
az login
```
Follow the instructions to complete the sign-in process.
1. Create an Azure service principal:
```azurecli
az ad sp create-for-rbac --name "uuuuuuuu" --password "pppppppp"
```
Where `uuuuuuuu` is the user name and `pppppppp` is the password for the service principal.
1. Azure responds with JSON that resembles the following example:
```json
{
"appId": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"displayName": "uuuuuuuu",
"name": "http://uuuuuuuu",
"password": "pppppppp",
"tenant": "tttttttt-tttt-tttt-tttt-tttttttttttt"
}
```
> [!NOTE]
>
> You will use the values from this JSON response when you configure the Maven plugin to deploy your container to Azure. The `aaaaaaaa`, `uuuuuuuu`, `pppppppp`, and `tttttttt` are placeholder values, which are used in this example to make it easier to map these values to their respective elements when you configure your Maven `settings.xml` file in the next section.
>
>
## Create an Azure Container Registry using the Azure CLI
1. Open a command prompt.
1. Log in to your Azure account:
```azurecli
az login
```
1. Create a resource group for the Azure resources you will use in this article:
```azurecli
az group create --name=wingtiptoysresources --location=westus
```
Replace `wingtiptoysresources` in this example with a unique name for your resource group.
1. Create a private Azure container registry in the resource group for your Spring Boot app:
```azurecli
az acr create --admin-enabled --resource-group wingtiptoysresources --location westus --name wingtiptoysregistry --sku Basic
```
Replace `wingtiptoysregistry` in this example with a unique name for your container registry.
1. Retrieve the password for your container registry:
```azurecli
az acr credential show --name wingtiptoysregistry --query passwords[0]
```
Azure will respond with your password; for example:
```json
{
"name": "password",
"value": "xxxxxxxxxx"
}
```
## Add your Azure container registry and Azure service principal to your Maven settings
1. Open your Maven `settings.xml` file in a text editor; this file might be in a path like the following examples:
* `/etc/maven/settings.xml`
* `%ProgramFiles%\apache-maven\3.5.0\conf\settings.xml`
* `$HOME/.m2/settings.xml`
1. Add your Azure Container Registry access settings from the previous section of this article to the `<servers>` collection in the *settings.xml* file; for example:
```xml
<servers>
<server>
<id>wingtiptoysregistry</id>
<username>wingtiptoysregistry</username>
<password>xxxxxxxxxx</password>
</server>
</servers>
```
Where:
Element | Description
---|---|---
`<id>` | Contains the name of your private Azure container registry.
`<username>` | Contains the name of your private Azure container registry.
`<password>` | Contains the password you retrieved in the previous section of this article.
1. Add your Azure service principal settings from an earlier section of this article to the `<servers>` collection in the *settings.xml* file; for example:
```xml
<servers>
<server>
<id>azure-auth</id>
<configuration>
<client>aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa</client>
<tenant>tttttttt-tttt-tttt-tttt-tttttttttttt</tenant>
<key>pppppppp</key>
<environment>AZURE</environment>
</configuration>
</server>
</servers>
```
Where:
Element | Description
---|---|---
`<id>` | Specifies a unique name which Maven uses to look up your security settings when you deploy your web app to Azure.
`<client>` | Contains the `appId` value from your service principal.
`<tenant>` | Contains the `tenant` value from your service principal.
`<key>` | Contains the `password` value from your service principal.
`<environment>` | Defines the target Azure cloud environment, which is `AZURE` in this example. (A full list of environments is available in the [Maven Plugin for Azure Web Apps] documentation)
1. Save and close the *settings.xml* file.
## Build your Docker container image and push it to your Azure container registry
1. Navigate to the completed project directory for your Spring Boot application, (e.g. "*C:\SpringBoot\gs-spring-boot-docker\complete*" or "*/users/robert/SpringBoot/gs-spring-boot-docker/complete*"), and open the *pom.xml* file with a text editor.
1. Update the `<properties>` collection in the *pom.xml* file with the login server value for your Azure Container Registry from the previous section of this tutorial; for example:
```xml
<properties>
<azure.containerRegistry>wingtiptoysregistry</azure.containerRegistry>
<docker.image.prefix>${azure.containerRegistry}.azurecr.io</docker.image.prefix>
<java.version>1.8</java.version>
<maven.build.timestamp.format>yyyyMMddHHmmssSSS</maven.build.timestamp.format>
</properties>
```
Where:
Element | Description
---|---|---
`<azure.containerRegistry>` | Specifies the name of your private Azure container registry.
`<docker.image.prefix>` | Specifies the URL of your private Azure container registry, which is derived by appending ".azurecr.io" to the name of your private container registry.
1. Verify that `<plugin>` for the Docker plugin in your *pom.xml* file contains the correct properties for the login server address and registry name from the previous step in this tutorial. For example:
```xml
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.11</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<registryUrl>https://${docker.image.prefix}</registryUrl>
<serverId>${azure.containerRegistry}</serverId>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
```
Where:
Element | Description
---|---|---
`<serverId>` | Specifies the property which contains name of your private Azure container registry.
`<registryUrl>` | Specifies the property which contains the URL of your private Azure container registry.
1. Navigate to the completed project directory for your Spring Boot application and run the following command to rebuild the application and push the container to your Azure container registry:
```
mvn package docker:build -DpushImage
```
1. OPTIONAL: Browse to the [Azure portal] and verify that there is Docker container image named **gs-spring-boot-docker** in your container registry.
![Verify container in Azure portal][CR01]
## Customize your pom.xml, then build and deploy your container to Azure
Open the `pom.xml` file for your Spring Boot application in a text editor, and then locate the `<plugin>` element for `azure-webapp-maven-plugin`. This element should resemble the following example:
```xml
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>0.1.3</version>
<configuration>
<authentication>
<serverId>azure-auth</serverId>
</authentication>
<resourceGroup>wingtiptoysresources</resourceGroup>
<appName>maven-linux-app-${maven.build.timestamp}</appName>
<region>westus</region>
<containerSettings>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<registryUrl>https://${docker.image.prefix}</registryUrl>
<serverId>${azure.containerRegistry}</serverId>
</containerSettings>
<appSettings>
<property>
<name>PORT</name>
<value>8080</value>
</property>
</appSettings>
</configuration>
</plugin>
```
There are several values that you can modify for the Maven plugin, and a detailed description for each of these elements is available in the [Maven Plugin for Azure Web Apps] documentation. That being said, there are several values that are worth highlighting in this article:
Element | Description
---|---|---
`<version>` | Specifies the version of the [Maven Plugin for Azure Web Apps]. You should check the version listed in the [Maven Central Respository](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22azure-webapp-maven-plugin%22) to ensure that you are using the latest version.
`<authentication>` | Specifies the authentication information for Azure, which in this example contains a `<serverId>` element that contains `azure-auth`; Maven uses that value to look up the Azure service principal values in your Maven *settings.xml* file, which you defined in an earlier section of this article.
`<resourceGroup>` | Specifies the target resource group, which is `wingtiptoysresources` in this example. The resource group will be created during deployment if it does not already exist.
`<appName>` | Specifies the target name for your web app. In this example, the target name is `maven-linux-app-${maven.build.timestamp}`, where the `${maven.build.timestamp}` suffix is appended in this example to avoid conflict. (The timestamp is optional; you can specify any unique string for the app name.)
`<region>` | Specifies the target region, which in this example is `westus`. (A full list is in the [Maven Plugin for Azure Web Apps] documentation.)
`<containerSettings>` | Specifies the properties which contain the name and URL of your container.
`<appSettings>` | Specifies any unique settings for Maven to use when deploying your web app to Azure. In this example, a `<property>` element contains a name/value pair of child elements that specify the port for your app.
> [!NOTE]
>
> The settings to change the port number in this example are only necessary when you are changing the port from the default.
>
1. From the command prompt or terminal window that you were using earlier, rebuild the JAR file using Maven if you made any changes to the *pom.xml* file; for example:
```shell
mvn clean package
```
1. Deploy your web app to Azure by using Maven; for example:
```shell
mvn azure-webapp:deploy
```
Maven will deploy your web app to Azure; if the web app does not already exist, it will be created.
> [!NOTE]
>
> If the region which you specify in the `<region>` element of your *pom.xml* file does not have enough servers available when you start your deployment, you might see an error similar to the following example:
>
> ```
> [INFO] Start deploying to Web App maven-linux-app-20170804...
> [INFO] ------------------------------------------------------------------------
> [INFO] BUILD FAILURE
> [INFO] ------------------------------------------------------------------------
> [INFO] Total time: 31.059 s
> [INFO] Finished at: 2017-08-04T12:15:47-07:00
> [INFO] Final Memory: 51M/279M
> [INFO] ------------------------------------------------------------------------
> [ERROR] Failed to execute goal com.microsoft.azure:azure-webapp-maven-plugin:0.1.3:deploy (default-cli) on project gs-spring-boot-docker: null: MojoExecutionException: CloudException: OnError while emitting onNext value: retrofit2.Response.class
> ```
>
> If this happens, you can specify another region and re-run the Maven command to deploy your application.
>
>
When your web has been deployed, you will be able to manage it by using the [Azure portal].
* Your web app will be listed in **App Services**:
![Web app listed in Azure portal App Services][AP01]
* And the URL for your web app will be listed in the **Overview** for your web app:
![Determining the URL for your web app][AP02]
## Next steps
For more information about the various technologies discussed in this article, see the following articles:
* [Maven Plugin for Azure Web Apps]
* [Log in to Azure from the Azure CLI](/azure/xplat-cli-connect)
* [Create an Azure service principal with Azure CLI 2.0](/cli/azure/create-an-azure-service-principal-azure-cli)
* [Maven Settings Reference](https://maven.apache.org/settings.html)
* [Docker plugin for Maven]
<!-- URL List -->
[Azure Command-Line Interface (CLI)]: /cli/azure/overview
[Azure Container Service (ACS)]: https://azure.microsoft.com/services/container-service/
[Azure Java Developer Center]: https://azure.microsoft.com/develop/java/
[Azure portal]: https://portal.azure.com/
[Maven Plugin for Azure Web Apps]: https://github.com/Microsoft/azure-maven-plugins/tree/master/azure-webapp-maven-plugin
[Create a private Docker container registry using the Azure portal]: /azure/container-registry/container-registry-get-started-portal
[Using a custom Docker image for Azure Web App on Linux]: /azure/app-service/containers/tutorial-custom-docker-image
[Docker]: https://www.docker.com/
[Docker plugin for Maven]: https://github.com/spotify/docker-maven-plugin
[free Azure account]: https://azure.microsoft.com/pricing/free-trial/
[Git]: https://github.com/
[Java Developer Kit (JDK)]: http://www.oracle.com/technetwork/java/javase/downloads/
[Java Tools for Visual Studio Team Services]: https://java.visualstudio.com/
[Maven]: http://maven.apache.org/
[MSDN subscriber benefits]: https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/
[Spring Boot]: http://projects.spring.io/spring-boot/
[Spring Boot on Docker Getting Started]: https://github.com/spring-guides/gs-spring-boot-docker
[Spring Framework]: https://spring.io/
<!-- IMG List -->
[SB01]: ./media/deploy-spring-boot-java-app-from-container-registry-using-maven-plugin/SB01.png
[CR01]: ./media/deploy-spring-boot-java-app-from-container-registry-using-maven-plugin/CR01.png
[AP01]: ./media/deploy-spring-boot-java-app-from-container-registry-using-maven-plugin/AP01.png
[AP02]: ./media/deploy-spring-boot-java-app-from-container-registry-using-maven-plugin/AP02.png
[TL01]: ./media/deploy-spring-boot-java-app-from-container-registry-using-maven-plugin/TL01.png

Просмотреть файл

@ -0,0 +1,363 @@
---
title: Deploy a Spring Boot App on Kubernetes in Azure Container Service
description: This tutorial will walk you though the steps to deploy a Spring Boot application in a Kubernetes cluster on Microsoft Azure.
services: container-service
documentationcenter: java
author: rmcmurray
manager: routlaw
editor: ''
keywords: Spring, Spring Boot, Spring Framework, Kubernetes
ms.assetid:
ms.service: multiple
ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: java
ms.topic: article
ms.date: 10/11/2017
ms.author: asirveda;robmcm
ms.custom: mvc
---
# Deploy a Spring Boot Application on a Kubernetes Cluster in the Azure Container Service
The **[Spring Framework]** is a popular open-source framework that helps Java developers create web, mobile, and API applications. This tutorial uses a sample app created using [Spring Boot], a convention-driven approach for using Spring to get started quickly.
**[Kubernetes]** and **[Docker]** are open-source solutions that help developers automate the deployment, scaling, and management of their applications running in containers.
This tutorial walks you though combining these two popular, open-source technologies to develop and deploy a Spring Boot application to Microsoft Azure. More specifically, you use *[Spring Boot]* for application development, *[Kubernetes]* for container deployment, and the [Azure Container Service (ACS)] to host your application.
### Prerequisites
* An Azure subscription; if you don't already have an Azure subscription, you can activate your [MSDN subscriber benefits] or sign up for a [free Azure account].
* The [Azure Command-Line Interface (CLI)].
* An up-to-date [Java Developer Kit (JDK)].
* Apache's [Maven] build tool (Version 3).
* A [Git] client.
* A [Docker] client.
> [!NOTE]
>
> Due to the virtualization requirements of this tutorial, you cannot follow the steps in this article on a virtual machine; you must use a physical computer with virtualization features enabled.
>
## Create the Spring Boot on Docker Getting Started web app
The following steps walk you through building a Spring Boot web application and testing it locally.
1. Open a command-prompt and create a local directory to hold your application, and change to that directory; for example:
```
md C:\SpringBoot
cd C:\SpringBoot
```
-- or --
```
md /users/robert/SpringBoot
cd /users/robert/SpringBoot
```
1. Clone the [Spring Boot on Docker Getting Started] sample project into the directory.
```
git clone https://github.com/spring-guides/gs-spring-boot-docker.git
```
1. Change directory to the completed project.
```
cd gs-spring-boot-docker
cd complete
```
1. Use Maven to build and run the sample app.
```
mvn package spring-boot:run
```
1. Test the web app by browsing to http://localhost:8080, or with the following `curl` command:
```
curl http://localhost:8080
```
1. You should see the following message displayed: **Hello Docker World**
![Browse Sample App Locally][SB01]
## Create an Azure Container Registry using the Azure CLI
1. Open a command prompt.
1. Log in to your Azure account:
```azurecli
az login
```
1. Create a resource group for the Azure resources used in this tutorial.
```azurecli
az group create --name=wingtiptoys-kubernetes --location=eastus
```
1. Create a private Azure container registry in the resource group. The tutorial pushes the sample app as a Docker image to this registry in later steps. Replace `wingtiptoysregistry` with a unique name for your registry.
```azurecli
az acr create --admin-enabled --resource-group wingtiptoys-kubernetes--location eastus \
--name wingtiptoysregistry --sku Basic
```
## Push your app to the container registry
1. Navigate to the configuration directory for your Maven installation (default ~/.m2/ or C:\Users\username\.m2) and open the *settings.xml* file with a text editor.
1. Retrieve the password for your container registry from the Azure CLI.
```azurecli
az acr credential show --name wingtiptoysregistry --query passwords[0]
```
```json
{
"name": "password",
"value": "AbCdEfGhIjKlMnOpQrStUvWxYz"
}
```
1. Add your Azure Container Registry id and password to a new `<server>` collection in the *settings.xml* file.
The `id` and `username` are the name of the registry. Use the `password` value from the previous command (without quotes).
```xml
<servers>
<server>
<id>wingtiptoysregistry</id>
<username>wingtiptoysregistry</username>
<password>AbCdEfGhIjKlMnOpQrStUvWxYz</password>
</server>
</servers>
```
1. Navigate to the completed project directory for your Spring Boot application (for example, "*C:\SpringBoot\gs-spring-boot-docker\complete*" or "*/users/robert/SpringBoot/gs-spring-boot-docker/complete*"), and open the *pom.xml* file with a text editor.
1. Update the `<properties>` collection in the *pom.xml* file with the login server value for your Azure Container Registry.
```xml
<properties>
<docker.image.prefix>wingtiptoysregistry.azurecr.io</docker.image.prefix>
<java.version>1.8</java.version>
</properties>
```
1. Update the `<plugins>` collection in the *pom.xml* file so that the `<plugin>` contains the login server address and registry name for your Azure Container Registry.
```xml
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.11</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<serverId>wingtiptoysregistry</serverId>
<registryUrl>https://wingtiptoysregistry.azurecr.io</registryUrl>
</configuration>
</plugin>
```
1. Navigate to the completed project directory for your Spring Boot application and run the following command to build the Docker container and push the image to the registry:
```
mvn package docker:build -DpushImage
```
> [!NOTE]
>
> You may receive an error message that is similar to one of the following when Maven pushes the image to Azure:
>
> * `[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.11:build (default-cli) on project gs-spring-boot-docker: Exception caught: no basic auth credentials`
>
> * `[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.11:build (default-cli) on project gs-spring-boot-docker: Exception caught: Incomplete Docker registry authorization credentials. Please provide all of username, password, and email or none.`
>
> If you get this error, log in to Azure from the Docker command line.
>
> `docker login -u wingtiptoysregistry -p "AbCdEfGhIjKlMnOpQrStUvWxYz" wingtiptoysregistry.azurecr.io`
>
> Then push your container:
>
> `docker push wingtiptoysregistry.azurecr.io/gs-spring-boot-docker`
## Create a Kubernetes Cluster on ACS using the Azure CLI
1. Create a Kubernetes cluster in Azure Container Service. The following command creates a *kubernetes* cluster in the *wingtiptoys-kubernetes* resource group, with *wingtiptoys-containerservice* as the cluster name, and *wingtiptoys-kubernetes* as the DNS prefix:
```azurecli
az acs create --orchestrator-type=kubernetes --resource-group=wingtiptoys-kubernetes \
--name=wingtiptoys-containerservice --dns-prefix=wingtiptoys-kubernetes
```
This command may take a while to complete.
1. Install `kubectl` using the Azure CLI. Linux users may have to prefix this command with `sudo` since it deploys the Kubernetes CLI to `/usr/local/bin`.
```azurecli
az acs kubernetes install-cli
```
1. Download the cluster configuration information so you can manage your cluster from the Kubernetes web interface and `kubectl`.
```azurecli
az acs kubernetes get-credentials --resource-group=wingtiptoys-kubernetes \
--name=wingtiptoys-containerservice
```
## Deploy the image to your Kubernetes cluster
This tutorial deploys the app using `kubectl`, then allow you to explore the deployment through the Kubernetes web interface.
### Deploy with the Kubernetes web interface
1. Open a command prompt.
1. Open the configuration website for your Kubernetes cluster in your default browser:
```
az acs kubernetes browse --resource-group=wingtiptoys-kubernetes --name=wingtiptoys-containerservice
```
1. When the Kubernetes configuration website opens in your browser, click the link to **deploy a containerized app**:
![Kubernetes Configuration Website][KB01]
1. When the **Deploy a containerized app** page is displayed, specify the following options:
a. Select **Specify app details below**.
b. Enter your Spring Boot application name for the **App name**; for example: "*gs-spring-boot-docker*".
c. Enter your login server and container image from earlier for the **Container image**; for example: "*wingtiptoysregistry.azurecr.io/gs-spring-boot-docker:latest*".
d. Choose **External** for the **Service**.
e. Specify your external and internal ports in the **Port** and **Target port** text boxes.
![Kubernetes Configuration Website][KB02]
1. Click **Deploy** to deploy the container.
![Deploy Container][KB05]
1. Once your application has been deployed, you will see your Spring Boot application listed under **Services**.
![Kubernetes Services][KB06]
1. If you click the link for **External endpoints**, you can see your Spring Boot application running on Azure.
![Kubernetes Services][KB07]
![Browse Sample App on Azure][SB02]
### Deploy with kubectl
1. Open a command prompt.
1. Run your container in the Kubernetes cluster by using the `kubectl run` command. Give a service name for your app in Kubernetes and the full image name. For example:
```
kubectl run gs-spring-boot-docker --image=wingtiptoysregistry.azurecr.io/gs-spring-boot-docker:latest
```
In this command:
* The container name `gs-spring-boot-docker` is specified immediately after the `run` command
* The `--image` parameter specifies the combined login server and image name as `wingtiptoysregistry.azurecr.io/gs-spring-boot-docker:latest`
1. Expose your Kubernetes cluster externally by using the `kubectl expose` command. Specify your service name, the public-facing TCP port used to access the app, and the internal target port your app listens on. For example:
```
kubectl expose deployment gs-spring-boot-docker --type=LoadBalancer --port=80 --target-port=8080
```
In this command:
* The container name `gs-spring-boot-docker` is specified immediately after the `expose deployment` command
* The `--type` parameter specifies that the cluster uses load balancer
* The `--port` parameter specifies the public-facing TCP port of 80. You access the app on this port.
* The `--target-port` parameter specifies the internal TCP port of 8080. The load balancer forwards requests to your app on this port.
1. Once the app is deployed to the cluster, query the external IP address and open it in your web browser:
```
kubectl get services -o jsonpath={.items[*].status.loadBalancer.ingress[0].ip} --namespace=${namespace}
```
![Browse Sample App on Azure][SB02]
## Next steps
For more information about using Spring Boot on Azure, see the following articles:
* [Deploy a Spring Boot Application to the Azure App Service](deploy-spring-boot-java-web-app-on-azure.md)
* [Deploy a Spring Boot application on Linux in the Azure Container Service](deploy-spring-boot-java-app-on-linux.md)
For more information about using Azure with Java, see the [Azure Java Developer Center] and the [Java Tools for Visual Studio Team Services].
For more information about the Spring Boot on Docker sample project, see [Spring Boot on Docker Getting Started].
The following links provide additional information about creating Spring Boot applications:
* For more information about creating a simple Spring Boot application, see the Spring Initializr at https://start.spring.io/.
The following links provide additional information about using Kubernetes with Azure:
* [Get started with a Kubernetes cluster in Container Service](https://docs.microsoft.com/azure/container-service/container-service-kubernetes-walkthrough)
* [Using the Kubernetes web UI with Azure Container Service](https://docs.microsoft.com/azure/container-service/container-service-kubernetes-ui)
More information about using Kubernetes command-line interface is available in the **kubectl** user guide at <https://kubernetes.io/docs/user-guide/kubectl/>.
The Kubernetes website has several articles that discuss using images in private registries:
* [Configuring Service Accounts for Pods]
* [Namespaces]
* [Pulling an Image from a Private Registry]
For additional examples for how to use custom Docker images with Azure, see [Using a custom Docker image for Azure Web App on Linux].
<!-- URL List -->
[Azure Command-Line Interface (CLI)]: /cli/azure/overview
[Azure Container Service (ACS)]: https://azure.microsoft.com/services/container-service/
[Azure Java Developer Center]: https://azure.microsoft.com/develop/java/
[Azure portal]: https://portal.azure.com/
[Create a private Docker container registry using the Azure portal]: /azure/container-registry/container-registry-get-started-portal
[Using a custom Docker image for Azure Web App on Linux]: /azure/app-service-web/app-service-linux-using-custom-docker-image
[Docker]: https://www.docker.com/
[free Azure account]: https://azure.microsoft.com/pricing/free-trial/
[Git]: https://github.com/
[Java Developer Kit (JDK)]: http://www.oracle.com/technetwork/java/javase/downloads/
[Java Tools for Visual Studio Team Services]: https://java.visualstudio.com/
[Kubernetes]: https://kubernetes.io/
[Kubernetes Command-Line Interface (kubectl)]: https://kubernetes.io/docs/user-guide/kubectl-overview/
[Maven]: http://maven.apache.org/
[MSDN subscriber benefits]: https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/
[Spring Boot]: http://projects.spring.io/spring-boot/
[Spring Boot on Docker Getting Started]: https://github.com/spring-guides/gs-spring-boot-docker
[Spring Framework]: https://spring.io/
[Configuring Service Accounts for Pods]: https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/
[Namespaces]: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
[Pulling an Image from a Private Registry]: https://kubernetes.io/docs/tasks/configure-pod-container/pull-image-private-registry/
<!-- IMG List -->
[SB01]: ./media/deploy-spring-boot-java-app-on-kubernetes/SB01.png
[SB02]: ./media/deploy-spring-boot-java-app-on-kubernetes/SB02.png
[AR01]: ./media/deploy-spring-boot-java-app-on-kubernetes/AR01.png
[AR02]: ./media/deploy-spring-boot-java-app-on-kubernetes/AR02.png
[AR03]: ./media/deploy-spring-boot-java-app-on-kubernetes/AR03.png
[AR04]: ./media/deploy-spring-boot-java-app-on-kubernetes/AR04.png
[KB01]: ./media/deploy-spring-boot-java-app-on-kubernetes/KB01.png
[KB02]: ./media/deploy-spring-boot-java-app-on-kubernetes/KB02.png
[KB03]: ./media/deploy-spring-boot-java-app-on-kubernetes/KB03.png
[KB04]: ./media/deploy-spring-boot-java-app-on-kubernetes/KB04.png
[KB05]: ./media/deploy-spring-boot-java-app-on-kubernetes/KB05.png
[KB06]: ./media/deploy-spring-boot-java-app-on-kubernetes/KB06.png
[KB07]: ./media/deploy-spring-boot-java-app-on-kubernetes/KB07.png

Просмотреть файл

@ -0,0 +1,313 @@
---
title: Deploy a Spring Boot Web App on Linux in Azure Container Service
description: This tutorial walks you though the steps to deploy a Spring Boot application as a Linux web app on Microsoft Azure.
services: container-service
documentationcenter: java
author: rmcmurray
manager: routlaw
editor: ''
keywords: Spring, Spring Boot, Spring Framework
ms.assetid:
ms.service: container-service
ms.workload: web
ms.tgt_pltfrm: multiple
ms.devlang: java
ms.topic: article
ms.date: 10/11/2017
ms.author: asirveda;robmcm
ms.custom: mvc
---
# Deploy a Spring Boot application on Linux in the Azure Container Service
The **[Spring Framework]** is an open-source solution that helps Java developers create enterprise-level applications. One of the more-popular projects that is built on top of that platform is [Spring Boot], which provides a simplified approach for creating stand-alone Java applications.
**[Docker]** is open-source solutions that helps developers automate the deployment, scaling, and management of their applications that are running in containers.
This tutorial walks you through using Docker to develop and deploy a Spring Boot application to a Linux host in the [Azure Container Service (ACS)].
## Prerequisites
In order to complete the steps in this tutorial, you need to have the following prerequisites:
* An Azure subscription; if you don't already have an Azure subscription, you can activate your [MSDN subscriber benefits] or sign up for a [free Azure account].
* The [Azure Command-Line Interface (CLI)].
* An up-to-date [Java Developer Kit (JDK)].
* Apache's [Maven] build tool (Version 3).
* A [Git] client.
* A [Docker] client.
> [!NOTE]
>
> Due to the virtualization requirements of this tutorial, you cannot follow the steps in this article on a virtual machine; you must use a physical computer with virtualization features enabled.
>
## Create the Spring Boot on Docker Getting Started web app
The following steps walk you through the steps that are required to create a simple Spring Boot web application and test it locally.
1. Open a command-prompt and create a local directory to hold your application, and change to that directory; for example:
```
md C:\SpringBoot
cd C:\SpringBoot
```
-- or --
```
md /users/robert/SpringBoot
cd /users/robert/SpringBoot
```
1. Clone the [Spring Boot on Docker Getting Started] sample project into the directory you created; for example:
```
git clone https://github.com/spring-guides/gs-spring-boot-docker.git
```
1. Change directory to the completed project; for example:
```
cd gs-spring-boot-docker/complete
```
1. Build the JAR file using Maven; for example:
```
mvn package
```
1. Once the web app has been created, change directory to the `target` directory where the JAR file is located and start the web app; for example:
```
cd target
java -jar gs-spring-boot-docker-0.1.0.jar
```
1. Test the web app by browsing to it locally using a web browser. For example, if you have curl available and you configured the Tomcat server to run on port 80:
```
curl http://localhost
```
1. You should see the following message displayed: **Hello Docker World!**
![Browse Sample App Locally][SB01]
## Create an Azure Container Registry to use as a Private Docker Registry
The following steps walk you through using the Azure portal to create an Azure Container Registry.
> [!NOTE]
>
> If you want to use the Azure CLI instead of the Azure portal, follow the steps in [Create a private Docker container registry using the Azure CLI 2.0](/azure/container-registry/container-registry-get-started-azure-cli).
>
1. Browse to the [Azure portal] and sign in.
Once you have signed in to your account on the Azure portal, you can follow the steps in the [Create a private Docker container registry using the Azure portal] article, which are paraphrased in the following steps for the sake of expediency.
1. Click the menu icon for **+ New**, then click **Containers**, and then click **Azure Container Registry**.
![Create a new Azure Container Registry][AR01]
1. When the information page for the Azure Container Registry template is displayed, click **Create**.
![Create a new Azure Container Registry][AR02]
1. When the **Create container registry** page is displayed, enter your **Registry name** and **Resource group**, choose **Enable** for the **Admin user**, and then click **Create**.
![Configure Azure Container Registry settings][AR03]
1. Once your container registry has been created, navigate to your container registry in the Azure portal, and then click **Access Keys**. Take note of the username and password for the next steps.
![Azure Container Registry access keys][AR04]
## Configure Maven to use your Azure Container Registry access keys
1. Navigate to the configuration directory for your Maven installation and open the *settings.xml* file with a text editor.
1. Add your Azure Container Registry access settings from the previous section of this tutorial to the `<servers>` collection in the *settings.xml* file; for example:
```xml
<servers>
<server>
<id>wingtiptoysregistry</id>
<username>wingtiptoysregistry</username>
<password>AbCdEfGhIjKlMnOpQrStUvWxYz</password>
</server>
</servers>
```
1. Navigate to the completed project directory for your Spring Boot application, (for example: "*C:\SpringBoot\gs-spring-boot-docker\complete*" or "*/users/robert/SpringBoot/gs-spring-boot-docker/complete*"), and open the *pom.xml* file with a text editor.
1. Update the `<properties>` collection in the *pom.xml* file with the login server value for your Azure Container Registry from the previous section of this tutorial; for example:
```xml
<properties>
<docker.image.prefix>wingtiptoysregistry.azurecr.io</docker.image.prefix>
<java.version>1.8</java.version>
</properties>
```
1. Update the `<plugins>` collection in the *pom.xml* file so that the `<plugin>` contains the login server address and registry name for your Azure Container Registry from the previous section of this tutorial. For example:
```xml
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>0.4.11</version>
<configuration>
<imageName>${docker.image.prefix}/${project.artifactId}</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
<serverId>wingtiptoysregistry</serverId>
<registryUrl>https://wingtiptoysregistry.azurecr.io</registryUrl>
</configuration>
</plugin>
```
1. Navigate to the completed project directory for your Spring Boot application and run the following command to rebuild the application and push the container to your Azure Container Registry:
```
mvn package docker:build -DpushImage
```
> [!NOTE]
>
> When you are pushing your Docker container to Azure, you may receive an error message that is similar to one of the following even though your Docker container was created successfully:
>
> * `[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.11:build (default-cli) on project gs-spring-boot-docker: Exception caught: no basic auth credentials`
>
> * `[ERROR] Failed to execute goal com.spotify:docker-maven-plugin:0.4.11:build (default-cli) on project gs-spring-boot-docker: Exception caught: Incomplete Docker registry authorization credentials. Please provide all of username, password, and email or none.`
>
> If this happens, you may need to sign in to your Azure account from the Docker command line; for example:
>
> `docker login -u wingtiptoysregistry -p "AbCdEfGhIjKlMnOpQrStUvWxYz" wingtiptoysregistry.azurecr.io`
>
> You can then push your container from the command line; for example:
>
> `docker push wingtiptoysregistry.azurecr.io/gs-spring-boot-docker`
>
## Create a web app on Linux on Azure App Service using your container image
1. Browse to the [Azure portal] and sign in.
1. Click the menu icon for **+ New**, then click **Web + Mobile**, and then click **Web App on Linux**.
![Create a new web app in the Azure portal][LX01]
1. When the **Web App on Linux** page is displayed, enter the following information:
a. Enter a unique name for the **App name**; for example: "*wingtiptoyslinux*."
b. Choose your **Subscription** from the drop-down list.
c. Choose an existing **Resource Group**, or specify a name to create a new resource group.
d. Click **Configure container** and enter the following information:
* Choose **Private registry**.
* **Image and optional tag**: Specify your container name from earlier; for example: "*wingtiptoysregistry.azurecr.io/gs-spring-boot-docker:latest*"
* **Server URL**: Specify your registry URL from earlier; for example: "*https://wingtiptoysregistry.azurecr.io*"
* **Login username** and **Password**: Specify your login credentials from your **Access Keys** that you used in previous steps.
e. Once you have entered all of the above information, click **OK**.
![Configure web app settings][LX02]
1. Click **Create**.
> [!NOTE]
>
> Azure will automatically map Internet requests to embedded Tomcat server that is running on the standard ports of 80 or 8080. However, if you configured your embedded Tomcat server to run on a custom port, you need to add an environment variable to your web app that defines the port for your embedded Tomcat server. To do so, use the following steps:
>
> 1. Browse to the [Azure portal] and sign in.
>
> 2. Click the icon for **App Services**. (See item #1 in the image below.)
>
> 3. Select your web app from the list. (Item #2 in the image below.)
>
> 4. Click **Application Settings**. (Item #3 in the image below.)
>
> 5. In the **App settings** section, add a new environment variable named **PORT** and enter your custom port number for the value. (Item #4 in the image below.)
>
> 6. Click **Save**. (Item #5 in the image below.)
>
> ![Saving a custom port number in the Azure portal][LX03]
>
<!--
## OPTIONAL: Configure the embedded Tomcat server to run on a different port
The embedded Tomcat server in the sample Spring Boot application is configured to run on port 8080 by default. However, if you want to run the embedded Tomcat server to run on a different port, such as port 80 for local testing, you can configure the port by using the following steps.
1. Go to the *resources* directory (or create the directory if it does not exist); for example:
```shell
cd src/main/resources
```
1. Open the *application.yml* file in a text editor if it exists, or create a new YAML file if it does not exist.
1. Modify the **server** setting so that the server runs on port 80; for example:
```yaml
server:
port: 80
```
1. Save and close the *application.yml* file.
-->
## Next steps
For more information about using Spring Boot applications on Azure, see the following articles:
* [Deploy a Spring Boot Application to the Azure App Service](deploy-spring-boot-java-web-app-on-azure.md)
* [Deploy a Spring Boot Application on a Kubernetes Cluster in the Azure Container Service](deploy-spring-boot-java-app-on-kubernetes.md)
For more information about using Azure with Java, see the [Azure Java Developer Center] and the [Java Tools for Visual Studio Team Services].
For further details about the Spring Boot on Docker sample project, see [Spring Boot on Docker Getting Started].
For help with getting started with your own Spring Boot applications, see the **Spring Initializr** at https://start.spring.io/.
For more information about getting started with creating a simple Spring Boot application, see the Spring Initializr at https://start.spring.io/.
For additional examples for how to use custom Docker images with Azure, see [Using a custom Docker image for Azure Web App on Linux].
<!-- URL List -->
[Azure Command-Line Interface (CLI)]: /cli/azure/overview
[Azure Container Service (ACS)]: https://azure.microsoft.com/services/container-service/
[Azure Java Developer Center]: https://azure.microsoft.com/develop/java/
[Azure portal]: https://portal.azure.com/
[Create a private Docker container registry using the Azure portal]: /azure/container-registry/container-registry-get-started-portal
[Using a custom Docker image for Azure Web App on Linux]: /azure/app-service-web/app-service-linux-using-custom-docker-image
[Docker]: https://www.docker.com/
[free Azure account]: https://azure.microsoft.com/pricing/free-trial/
[Git]: https://github.com/
[Java Developer Kit (JDK)]: http://www.oracle.com/technetwork/java/javase/downloads/
[Java Tools for Visual Studio Team Services]: https://java.visualstudio.com/
[Maven]: http://maven.apache.org/
[MSDN subscriber benefits]: https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/
[Spring Boot]: http://projects.spring.io/spring-boot/
[Spring Boot on Docker Getting Started]: https://github.com/spring-guides/gs-spring-boot-docker
[Spring Framework]: https://spring.io/
<!-- IMG List -->
[SB01]: ./media/deploy-spring-boot-java-app-on-linux/SB01.png
[SB02]: ./media/deploy-spring-boot-java-app-on-linux/SB02.png
[AR01]: ./media/deploy-spring-boot-java-app-on-linux/AR01.png
[AR02]: ./media/deploy-spring-boot-java-app-on-linux/AR02.png
[AR03]: ./media/deploy-spring-boot-java-app-on-linux/AR03.png
[AR04]: ./media/deploy-spring-boot-java-app-on-linux/AR04.png
[LX01]: ./media/deploy-spring-boot-java-app-on-linux/LX01.png
[LX02]: ./media/deploy-spring-boot-java-app-on-linux/LX02.png
[LX03]: ./media/deploy-spring-boot-java-app-on-linux/LX03.png

Просмотреть файл

@ -0,0 +1,545 @@
---
title: Deploy a Spring Boot app using the Fabric8 Maven Plugin
description: This tutorial walks you though the steps to deploy a Spring Boot application on Microsoft Azure using the Fabric8 Plugin for Apache Maven.
services: container-service
documentationcenter: java
author: rmcmurray
manager: routlaw
editor: ''
keywords: Spring, Spring Boot, Spring Framework, Maven
ms.assetid:
ms.service: container-service
ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: java
ms.topic: article
ms.date: 10/11/2017
ms.author: yuwzho;robmcm
ms.custom:
---
# Deploy a Spring Boot app using the Fabric8 Maven Plugin
**[Fabric8]** is an open-source solution that is built on **[Kubernetes]**, which helps developers create applications in Linux containers.
This tutorial walks you through using the Fabric8 plugin for Maven to develop to deploy an application to a Linux host in the [Azure Container Service (ACS)].
## Prerequisites
In order to complete the steps in this tutorial, you need to have the following prerequisites:
* An Azure subscription; if you don't already have an Azure subscription, you can activate your [MSDN subscriber benefits] or sign up for a [free Azure account].
* The [Azure Command-Line Interface (CLI)].
* An up-to-date [Java Developer Kit (JDK)].
* Apache's [Maven] build tool (Version 3).
* A [Git] client.
* A [Docker] client.
> [!NOTE]
>
> Due to the virtualization requirements of this tutorial, you cannot follow the steps in this article on a virtual machine; you must use a physical computer with virtualization features enabled.
>
## Create the Spring Boot on Docker Getting Started web app
The following steps walk you through building a Spring Boot web application and testing it locally.
1. Open a command-prompt and create a local directory to hold your application, and change to that directory; for example:
```shell
md /home/GenaSoto/SpringBoot
cd /home/GenaSoto/SpringBoot
```
-- or --
```shell
md C:\SpringBoot
cd C:\SpringBoot
```
1. Clone the [Spring Boot on Docker Getting Started] sample project into the directory.
```shell
git clone https://github.com/spring-guides/gs-spring-boot-docker.git
```
1. Change directory to the completed project; for example:
```shell
cd gs-spring-boot-docker/complete
```
-- or --
```shell
cd gs-spring-boot-docker\complete
```
1. Use Maven to build and run the sample app.
```shell
mvn clean package spring-boot:run
```
1. Test the web app by browsing to http://localhost:8080, or with the following `curl` command:
```shell
curl http://localhost:8080
```
You should see a **Hello Docker World** message displayed.
![Browse sample application locally][SB01]
## Install the Kubernetes command-line interface and create an Azure resource group using the Azure CLI
1. Open a command prompt.
1. Type the following command to log in to your Azure account:
```azurecli
az login
```
Follow the instructions to complete the login process
The Azure CLI will display a list of your accounts; for example:
```json
[
{
"cloudName": "AzureCloud",
"id": "00000000-0000-0000-0000-000000000000",
"isDefault": false,
"name": "Windows Azure MSDN - Visual Studio Ultimate",
"state": "Enabled",
"tenantId": "00000000-0000-0000-0000-000000000000",
"user": {
"name": "Gena.Soto@wingtiptoys.com",
"type": "user"
}
}
]
```
1. If you do not already have the Kubernetes command-line interface (`kubectl`) installed, you can install using the Azure CLI; for example:
```azurecli
az acs kubernetes install-cli
```
> [!NOTE]
>
> Linux users may have to prefix this command with `sudo` since it deploys the Kubernetes CLI to `/usr/local/bin`.
>
> If you already have `kubectl`) installed and your version of `kubectl` is too old, you may see an error message similar to the following example when you attempt to complete the steps listed later in this article:
>
> ```
> error: group map[autoscaling:0x0000000000 batch:0x0000000000 certificates.k8s.io
> :0x0000000000 extensions:0x0000000000 storage.k8s.io:0x0000000000 apps:0x0000000
> 000 authentication.k8s.io:0x0000000000 policy:0x0000000000 rbac.authorization.k8
> s.io:0x0000000000 federation:0x0000000000 authorization.k8s.io:0x0000000000 comp
> onentconfig:0x0000000000] is already registered
> ```
>
> If this happens, you will need to reinstall `kubectl` to update your version.
>
1. Create a resource group for the Azure resources that you will use in this tutorial; for example:
```azurecli
az group create --name=wingtiptoys-kubernetes --location=westeurope
```
Where:
* *wingtiptoys-kubernetes* is a unique name for your resource group
* *westeurope* is an appropriate geographic location for your application
The Azure CLI will display the results of your resource group creation; for example:
```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/wingtiptoys-kubernetes",
"location": "westeurope",
"managedBy": null,
"name": "wingtiptoys-kubernetes",
"properties": {
"provisioningState": "Succeeded"
},
"tags": null
}
```
## Create a Kubernetes cluster using the Azure CLI
1. Create a Kubernetes cluster in your new resource group; for example:
```azurecli
az acs create --orchestrator-type kubernetes --resource-group wingtiptoys-kubernetes --name wingtiptoys-cluster --generate-ssh-keys --dns-prefix=wingtiptoys
```
Where:
* *wingtiptoys-kubernetes* is the name of your resource group from earlier in this article
* *wingtiptoys-cluster* is a unique name for your Kubernetes cluster
* *wingtiptoys* is a unique name DNS name for your application
The Azure CLI will display the results of your cluster creation; for example:
```json
{
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/wingtiptoys-kubernetes/providers/Microsoft.Resources/deployments/azurecli0000000000.00000000000",
"name": "azurecli0000000000.00000000000",
"properties": {
"correlationId": "00000000-0000-0000-0000-000000000000",
"debugSetting": null,
"dependencies": [],
"mode": "Incremental",
"outputs": {
"masterFQDN": {
"type": "String",
"value": "wingtiptoysmgmt.westeurope.cloudapp.azure.com"
},
"sshMaster0": {
"type": "String",
"value": "ssh azureuser@wingtiptoysmgmt.westeurope.cloudapp.azure.com -A -p 22"
}
},
"parameters": {
"clientSecret": {
"type": "SecureString"
}
},
"parametersLink": null,
"providers": [
{
"id": null,
"namespace": "Microsoft.ContainerService",
"registrationState": null,
"resourceTypes": [
{
"aliases": null,
"apiVersions": null,
"locations": [
"westeurope"
],
"properties": null,
"resourceType": "containerServices"
}
]
}
],
"provisioningState": "Succeeded",
"template": null,
"templateLink": null,
"timestamp": "2017-09-15T01:00:00.000000+00:00"
},
"resourceGroup": "wingtiptoys-kubernetes"
}
```
1. Download your credentials for your new Kubernetes cluster; for example:
```azurecli
az acs kubernetes get-credentials --resource-group=wingtiptoys-kubernetes --name wingtiptoys-cluster
```
1. Verify your connection with the following command:
```shell
kubectl get nodes
```
You should see a list of nodes and statuses like the following example:
```shell
NAME STATUS AGE VERSION
k8s-agent-00000000-0 Ready 5h v1.6.6
k8s-agent-00000000-1 Ready 5h v1.6.6
k8s-agent-00000000-2 Ready 5h v1.6.6
k8s-master-00000000-0 Ready,SchedulingDisabled 5h v1.6.6
```
## Create a private Azure container registry using the Azure CLI
1. Create a private Azure container registry in your resource group to host your Docker image; for example:
```azurecli
az acr create --admin-enabled --resource-group wingtiptoys-kubernetes --location westeurope --name wingtiptoysregistry --sku Basic
```
Where:
* *wingtiptoys-kubernetes* is the name of your resource group from earlier in this article
* *wingtiptoysregistry* is a unique name for your private registry
* *westeurope* is an appropriate geographic location for your application
The Azure CLI will display the results of your registry creation; for example:
```json
{
"adminUserEnabled": true,
"creationDate": "2017-09-15T01:00:00.000000+00:00",
"id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/wingtiptoys-kubernetes/providers/Microsoft.ContainerRegistry/registries/wingtiptoysregistry",
"location": "westeurope",
"loginServer": "wingtiptoysregistry.azurecr.io",
"name": "wingtiptoysregistry",
"provisioningState": "Succeeded",
"resourceGroup": "wingtiptoys-kubernetes",
"sku": {
"name": "Basic",
"tier": "Basic"
},
"storageAccount": {
"name": "wingtiptoysregistr000000"
},
"tags": {},
"type": "Microsoft.ContainerRegistry/registries"
}
```
1. Retrieve the password for your container registry from the Azure CLI.
```azurecli
az acr credential show --name wingtiptoysregistry --query passwords[0]
```
The Azure CLI will display the password for your registry; for example:
```json
{
"name": "password",
"value": "AbCdEfGhIjKlMnOpQrStUvWxYz"
}
```
1. Navigate to the configuration directory for your Maven installation (default ~/.m2/ or C:\Users\username\.m2) and open the *settings.xml* file with a text editor.
1. Add your Azure Container Registry URL, username and password to a new `<server>` collection in the *settings.xml* file.
The `id` and `username` are the name of the registry. Use the `password` value from the previous command (without quotes).
```xml
<servers>
<server>
<id>wingtiptoysregistry.azurecr.io</id>
<username>wingtiptoysregistry</username>
<password>AbCdEfGhIjKlMnOpQrStUvWxYz</password>
</server>
</servers>
```
1. Navigate to the completed project directory for your Spring Boot application (for example, "*C:\SpringBoot\gs-spring-boot-docker\complete*" or "*/home/GenaSoto/SpringBoot/gs-spring-boot-docker/complete*"), and open the *pom.xml* file with a text editor.
1. Update the `<properties>` collection in the *pom.xml* file with the login server value for your Azure Container Registry.
```xml
<properties>
<docker.image.prefix>wingtiptoysregistry.azurecr.io</docker.image.prefix>
<java.version>1.8</java.version>
</properties>
```
1. Update the `<plugins>` collection in the *pom.xml* file so that the `<plugin>` contains the login server address and registry name for your Azure Container Registry.
```xml
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.4</version>
<configuration>
<repository>${docker.image.prefix}/${project.artifactId}</repository>
<serverId>${docker.image.prefix}</serverId>
<registryUrl>https://${docker.image.prefix}</registryUrl>
</configuration>
</plugin>
```
1. Navigate to the completed project directory for your Spring Boot application, and run the following Maven command to build the Docker container and push the image to your registry:
```shell
mvn package dockerfile:build -DpushImage
```
Maven will display the results of your build; for example:
```shell
[INFO] ----------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------
[INFO] Total time: 38.113 s
[INFO] Finished at: 2017-09-15T02:00:00-07:00
[INFO] Final Memory: 47M/338M
[INFO] ----------------------------------------------------
```
## Configure your Spring Boot app to use the Fabric8 Maven plugin
1. Navigate to the completed project directory for your Spring Boot application, (for example: "*C:\SpringBoot\gs-spring-boot-docker\complete*" or "*/home/GenaSoto/SpringBoot/gs-spring-boot-docker/complete*"), and open the *pom.xml* file with a text editor.
1. Update the `<plugins>` collection in the *pom.xml* file to add the Fabric8 Maven plugin:
```xml
<plugin>
<groupId>io.fabric8</groupId>
<artifactId>fabric8-maven-plugin</artifactId>
<version>3.5.30</version>
<configuration>
<ignoreServices>false</ignoreServices>
<registry>${docker.image.prefix}</registry>
</configuration>
</plugin>
```
1. Navigate to the main source directory for your Spring Boot application, (for example: "*C:\SpringBoot\gs-spring-boot-docker\complete\src\main*" or "*/home/GenaSoto/SpringBoot/gs-spring-boot-docker/complete/src/main*"), and create a new folder named "*fabric8*".
1. Create three YAML fragment files in the new *fabric8* folder:
a. Create a file named **deployment.yml** with the following contents:
```yaml
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: ${project.artifactId}
labels:
run: gs-spring-boot-docker
spec:
replicas: 1
selector:
matchLabels:
run: gs-spring-boot-docker
strategy:
rollingUpdate:
maxSurge: 1
maxUnavailable: 1
type: RollingUpdate
template:
metadata:
labels:
run: gs-spring-boot-docker
spec:
containers:
- image: ${docker.image.prefix}/${project.artifactId}:latest
name: gs-spring-boot-docker
imagePullPolicy: Always
ports:
- containerPort: 8080
imagePullSecrets:
- name: mysecrets
```
b. Create a file named **secrets.yml** with the following contents:
```yaml
apiVersion: v1
kind: Secret
metadata:
name: mysecrets
namespace: default
annotations:
maven.fabric8.io/dockerServerId: ${docker.image.prefix}
type: kubernetes.io/dockercfg
```
c. Create a file named **service.yml** with the following contents:
```yaml
apiVersion: v1
kind: Service
metadata:
name: ${project.artifactId}
labels:
expose: "true"
spec:
ports:
- port: 80
targetPort: 8080
type: LoadBalancer
```
1. Run the following Maven command to build the Kubernetes resource list file:
```shell
mvn fabric8:resource
```
This command merges all Kubernetes resource yaml files under the *src/main/fabric8* folder to a YAML file that contains a Kubernetes resource list, which can be applied to Kubernetes cluster directly or export to a helm chart.
Maven will display the results of your build; for example:
```shell
[INFO] ----------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------
[INFO] Total time: 16.744 s
[INFO] Finished at: 2017-09-15T02:35:00-07:00
[INFO] Final Memory: 30M/290M
[INFO] ----------------------------------------------------
```
1. Run the following Maven command to apply the resource list file to your Kubernetes cluster:
```shell
mvn fabric8:apply
```
Maven will display the results of your build; for example:
```shell
[INFO] ----------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ----------------------------------------------------
[INFO] Total time: 14.814 s
[INFO] Finished at: 2017-09-15T02:41:00-07:00
[INFO] Final Memory: 35M/288M
[INFO] ----------------------------------------------------
```
1. Once the app is deployed to the cluster, query the external IP address using the `kubectl` application; for example:
```shell
kubectl get svc -w
```
`kubectl` will display your internal and external IP addresses; for example:
```shell
NAME CLUSTER-IP EXTERNAL-IP PORT(S) AGE
kubernetes 10.0.0.1 <none> 443/TCP 19h
gs-spring-boot-docker 10.0.242.8 13.65.196.3 80:31215/TCP 3m
```
You can use the external IP address to open your application in a web browser.
![Browse sample application externally][SB02]
## Delete your Kubernetes cluster
When your Kubernetes cluster is no longer needed, you can use the `az group delete` command to remove the resource group, which will remove all of its related resources; for example:
```azurecli
az group delete --name wingtiptoys-kubernetes --yes --no-wait
```
## Next steps
For more information about using Spring Boot applications on Azure, see the following articles:
* [Deploy a Spring Boot Application to the Azure App Service](deploy-spring-boot-java-web-app-on-azure.md)
* [Deploy a Spring Boot application on Linux in the Azure Container Service](deploy-spring-boot-java-app-on-linux.md)
* [Deploy a Spring Boot Application on a Kubernetes Cluster in the Azure Container Service](deploy-spring-boot-java-app-on-kubernetes.md)
For more information about using Azure with Java, see the [Azure Java Developer Center] and the [Java Tools for Visual Studio Team Services].
For further details about the Spring Boot on Docker sample project, see [Spring Boot on Docker Getting Started].
For help with getting started with your own Spring Boot applications, see the **Spring Initializr** at <https://start.spring.io/>.
For more information about getting started with creating a simple Spring Boot application, see the Spring Initializr at <https://start.spring.io/>.
For additional examples for how to use custom Docker images with Azure, see [Using a custom Docker image for Azure Web App on Linux].
<!-- URL List -->
[Azure Command-Line Interface (CLI)]: /cli/azure/overview
[Azure Container Service (ACS)]: https://azure.microsoft.com/services/container-service/
[Azure Java Developer Center]: https://azure.microsoft.com/develop/java/
[Azure portal]: https://portal.azure.com/
[Create a private Docker container registry using the Azure portal]: /azure/container-registry/container-registry-get-started-portal
[Using a custom Docker image for Azure Web App on Linux]: /azure/app-service-web/app-service-linux-using-custom-docker-image
[Docker]: https://www.docker.com/
[Fabric8]: https://fabric8.io/
[free Azure account]: https://azure.microsoft.com/pricing/free-trial/
[Git]: https://github.com/
[Java Developer Kit (JDK)]: http://www.oracle.com/technetwork/java/javase/downloads/
[Java Tools for Visual Studio Team Services]: https://java.visualstudio.com/
[Kubernetes]: https://kubernetes.io/
[Maven]: http://maven.apache.org/
[MSDN subscriber benefits]: https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/
[Spring Boot]: http://projects.spring.io/spring-boot/
[Spring Boot on Docker Getting Started]: https://github.com/spring-guides/gs-spring-boot-docker
[Spring Framework]: https://spring.io/
<!-- IMG List -->
[SB01]: ./media/deploy-spring-boot-java-app-using-fabric8-maven-plugin/SB01.png
[SB02]: ./media/deploy-spring-boot-java-app-using-fabric8-maven-plugin/SB02.png

Просмотреть файл

@ -0,0 +1,285 @@
---
title: How to use the Maven Plugin for Azure Web Apps to deploy a Spring Boot app to Azure
description: Learn how to use the Maven Plugin for Azure Web Apps to deploy a Spring Boot app to Azure.
services: app-service
documentationcenter: java
author: rmcmurray
manager: routlaw
editor: ''
keywords: Spring, Spring Boot, Spring Framework, Maven
ms.assetid:
ms.service: app-service
ms.workload: web
ms.tgt_pltfrm: multiple
ms.devlang: java
ms.topic: article
ms.date: 10/11/2017
ms.author: robmcm;kevinzha
---
# How to use the Maven Plugin for Azure Web Apps to deploy a Spring Boot app to Azure
The [Maven Plugin for Azure Web Apps](https://github.com/Microsoft/azure-maven-plugins/tree/master/azure-webapp-maven-plugin) for [Apache Maven](http://maven.apache.org/) provides seamless integration of Azure App Service into Maven projects, and streamlines the process for developers to deploy web apps to Azure App Service.
This article demonstrates using the Maven Plugin for Azure Web Apps to deploy a sample Spring Boot application to Azure App Services.
> [!NOTE]
>
> The Maven Plugin for Azure Web Apps is currently available as a preview. For now, only FTP publishing is supported, although additional features are planned for the future.
>
## Prerequisites
In order to complete the steps in this tutorial, you need to have the following prerequisites:
* An Azure subscription; if you don't already have an Azure subscription, you can activate your [MSDN subscriber benefits] or sign up for a [free Azure account].
* The [Azure Command-Line Interface (CLI)].
* An up-to-date [Java Development Kit (JDK)], version 1.7 or later.
* Apache's [Maven] build tool (Version 3).
* A [Git] client.
## Clone the sample Spring Boot web app
In this section, you clone a completed Spring Boot application and test it locally.
1. Open a command prompt or terminal window and create a local directory to hold your Spring Boot application, and change to that directory; for example:
```shell
md C:\SpringBoot
cd C:\SpringBoot
```
-- or --
```shell
md /users/robert/SpringBoot
cd /users/robert/SpringBoot
```
1. Clone the [Spring Boot Getting Started] sample project into the directory you created; for example:
```shell
git clone https://github.com/microsoft/gs-spring-boot
```
1. Change directory to the completed project; for example:
```shell
cd gs-spring-boot/complete
```
1. Build the JAR file using Maven; for example:
```shell
mvn clean package
```
1. When the web app has been created, start the web app using Maven; for example:
```shell
mvn spring-boot:run
```
1. Test the web app by browsing to it locally using a web browser. For example, you could use the following command if you have curl available:
```shell
curl http://localhost:8080
```
1. You should see the following message displayed: **Greetings from Spring Boot!**
## Create an Azure service principal
In this section, you create an Azure service principal that the Maven plugin uses when deploying your web app to Azure.
1. Open a command prompt.
1. Sign into your Azure account by using the Azure CLI:
```shell
az login
```
Follow the instructions to complete the sign-in process.
1. Create an Azure service principal:
```shell
az ad sp create-for-rbac --name "uuuuuuuu" --password "pppppppp"
```
Where `uuuuuuuu` is the user name and `pppppppp` is the password for the service principal.
1. Azure responds with JSON that resembles the following example:
```json
{
"appId": "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
"displayName": "uuuuuuuu",
"name": "http://uuuuuuuu",
"password": "pppppppp",
"tenant": "tttttttt-tttt-tttt-tttt-tttttttttttt"
}
```
> [!NOTE]
>
> You will use the values from this JSON response when you configure the Maven plugin to deploy your web app to Azure. The `aaaaaaaa`, `uuuuuuuu`, `pppppppp`, and `tttttttt` are placeholder values, which are used in this example to make it easier to map these values to their respective elements when you configure your Maven `settings.xml` file in the next section.
>
>
## Configure Maven to use your Azure service principal
In this section, you use the values from your Azure service principal to configure the authentication that Maven uses when deploying your web app to Azure.
1. Open your Maven `settings.xml` file in a text editor; this file might be in a path like the following examples:
* `/etc/maven/settings.xml`
* `%ProgramFiles%\apache-maven\3.5.0\conf\settings.xml`
* `$HOME/.m2/settings.xml`
1. Add your Azure service principal settings from the previous section of this tutorial to the `<servers>` collection in the *settings.xml* file; for example:
```xml
<servers>
<server>
<id>azure-auth</id>
<configuration>
<client>aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa</client>
<tenant>tttttttt-tttt-tttt-tttt-tttttttttttt</tenant>
<key>pppppppp</key>
<environment>AZURE</environment>
</configuration>
</server>
</servers>
```
Where:
Element | Description
---|---|---
`<id>` | Specifies a unique name which Maven uses to look up your security settings when you deploy your web app to Azure.
`<client>` | Contains the `appId` value from your service principal.
`<tenant>` | Contains the `tenant` value from your service principal.
`<key>` | Contains the `password` value from your service principal.
`<environment>` | Defines the target Azure cloud environment, which is `AZURE` in this example. (A full list of environments is available in the [Maven Plugin for Azure Web Apps] documentation)
1. Save and close the *settings.xml* file.
## OPTIONAL: Customize your pom.xml before deploying your web app to Azure
Open the `pom.xml` file for your Spring Boot application in a text editor, and then locate the `<plugin>` element for `azure-webapp-maven-plugin`. This element should resemble the following example:
```xml
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-webapp-maven-plugin</artifactId>
<version>0.1.3</version>
<configuration>
<authentication>
<serverId>azure-auth</serverId>
</authentication>
<resourceGroup>maven-plugin</resourceGroup>
<appName>maven-web-app-${maven.build.timestamp}</appName>
<region>westus</region>
<javaVersion>1.8</javaVersion>
<deploymentType>ftp</deploymentType>
<resources>
<resource>
<directory>${project.basedir}/target</directory>
<targetPath>/</targetPath>
<includes>
<include>*.jar</include>
</includes>
</resource>
<resource>
<directory>${project.basedir}</directory>
<targetPath>/</targetPath>
<includes>
<include>web.config</include>
</includes>
</resource>
</resources>
</configuration>
</plugin>
```
There are several values that you can modify for the Maven plugin, and a detailed description for each of these elements is available in the [Maven Plugin for Azure Web Apps] documentation. That being said, there are several values that are worth highlighting in this article:
Element | Description
---|---|---
`<version>` | Specifies the version of the [Maven Plugin for Azure Web Apps]. You should check the version listed in the [Maven Central Respository](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22azure-webapp-maven-plugin%22) to ensure that you are using the latest version.
`<authentication>` | Specifies the authentication information for Azure, which in this example contains a `<serverId>` element that contains `azure-auth`; Maven uses that value to look up the Azure service principal values in your Maven *settings.xml* file, which you defined in an earlier section of this article.
`<resourceGroup>` | Specifies the target resource group, which is `maven-plugin` in this example. The resource group is created during deployment if it does not already exist.
`<appName>` | Specifies the target name for your web app. In this example, the target name is `maven-web-app-${maven.build.timestamp}`, where the `${maven.build.timestamp}` suffix is appended in this example to avoid conflict. (The timestamp is optional; you can specify any unique string for the app name.)
`<region>` | Specifies the target region, which in this example is `westus`. (A full list is in the [Maven Plugin for Azure Web Apps] documentation.)
`<javaVersion>` | Specifies the Java runtime version for your web app. (A full list is in the [Maven Plugin for Azure Web Apps] documentation.)
`<deploymentType>` | Specifies deployment type for your web app. For now, only `ftp` is supported, although support for other deployment types is in development.
`<resources>` | Specifies resources and target destinations which Maven uses when deploying your web app to Azure. In this example, two `<resource>` elements specify that Maven will deploy the JAR file for your web app and the *web.config* file from the Spring Boot project.
## Build and deploy your web app to Azure
Once you have configured all of the settings in the preceding sections of this article, you are ready to deploy your web app to Azure. To do so, use the following steps:
1. From the command prompt or terminal window that you were using earlier, rebuild the JAR file using Maven if you made any changes to the *pom.xml* file; for example:
```shell
mvn clean package
```
1. Deploy your web app to Azure by using Maven; for example:
```shell
mvn azure-webapp:deploy
```
Maven will deploy your web app to Azure; if the web app does not already exist, it will be created.
When your web has been deployed, you will be able to manage it by using the [Azure portal].
* Your web app will be listed in **App Services**:
![Web app listed in Azure portal App Services][AP01]
* And the URL for your web app will be listed in the **Overview** for your web app:
![Determining the URL for your web app][AP02]
<!--
## OPTIONAL: Configure the embedded Tomcat server to run on a different port
The embedded Tomcat server in the sample Spring Boot application is configured to run on port 8080 by default. However, if you want to run the embedded Tomcat server to run on a different port, such as port 80 for local testing, you can configure the port by using the following steps.
1. Go to the *resources* directory (or create the directory if it does not exist); for example:
```shell
cd src/main/resources
```
1. Open the *application.yml* file in a text editor if it exists, or create a new YAML file if it does not exist.
1. Modify the **server** setting so that the server runs on port 80; for example:
```yaml
server:
port: 80
```
1. Save and close the *application.yml* file.
-->
## Next steps
For more information about the various technologies discussed in this article, see the following articles:
* [Maven Plugin for Azure Web Apps]
* [Log in to Azure from the Azure CLI](/azure/xplat-cli-connect)
* [How to use the Maven Plugin for Azure Web Apps to deploy a containerized Spring Boot app to Azure](deploy-containerized-spring-boot-java-app-with-maven-plugin.md)
* [Create an Azure service principal with Azure CLI 2.0](/cli/azure/create-an-azure-service-principal-azure-cli)
* [Maven Settings Reference](https://maven.apache.org/settings.html)
<!-- URL List -->
[Azure Command-Line Interface (CLI)]: /cli/azure/overview
[Azure Java Developer Center]: https://azure.microsoft.com/develop/java/
[Azure portal]: https://portal.azure.com/
[free Azure account]: https://azure.microsoft.com/pricing/free-trial/
[Git]: https://github.com/
[Java Developer Kit (JDK)]: http://www.oracle.com/technetwork/java/javase/downloads/
[Java Tools for Visual Studio Team Services]: https://java.visualstudio.com/
[Maven]: http://maven.apache.org/
[MSDN subscriber benefits]: https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/
[Spring Boot]: http://projects.spring.io/spring-boot/
[Spring Boot Getting Started]: https://github.com/microsoft/gs-spring-boot
[Spring Framework]: https://spring.io/
[Maven Plugin for Azure Web Apps]: https://github.com/Microsoft/azure-maven-plugins/tree/master/azure-webapp-maven-plugin
<!-- IMG List -->
[AP01]: ./media/deploy-spring-boot-java-app-with-maven-plugin/AP01.png
[AP02]: ./media/deploy-spring-boot-java-app-with-maven-plugin/AP02.png

Просмотреть файл

@ -0,0 +1,241 @@
---
title: Deploy a Spring Boot Application to the Azure App Service
description: This tutorial will guide developers through the steps to deploy the Spring Boot Getting Started web app to Azure App Service.
services: app-service
documentationcenter: java
author: rmcmurray
manager: routlaw
editor: ''
keywords: Spring, Spring Boot, Spring Framework
ms.assetid:
ms.service: multiple
ms.workload: na
ms.tgt_pltfrm: multiple
ms.devlang: java
ms.topic: article
ms.date: 10/11/2017
ms.author: asirveda;robmcm
---
# Deploy a Spring Boot Application to the Azure App Service
The **[Spring Framework]** is an open-source solution which helps Java developers create enterprise-level applications, and one of the more-popular projects which is built on top of that platform is [Spring Boot], which provides a simplified approach for creating stand-alone Java applications.
This tutorial will walk you though creating the sample Spring Boot Getting Started web app and deploying it to [Azure App Service].
### Prerequisites
In order to complete the steps in this tutorial, you need to have the following:
* An Azure subscription; if you don't already have an Azure subscription, you can activate your [MSDN subscriber benefits] or sign up for a [free Azure account].
* An up-to-date [Java Developer Kit (JDK)].
* Apache's [Maven] build tool (Version 3).
* A [Git] client.
## Create the Spring Boot Getting Started web app
The following steps will walk you through the steps that are required to create a simple Spring Boot web application and test it locally.
1. Open a command-prompt and create a local directory to hold your application, and change to that directory; for example:
```
md C:\SpringBoot
cd C:\SpringBoot
```
-- or --
```
md /users/robert/SpringBoot
cd /users/robert/SpringBoot
```
1. Clone the [Spring Boot Getting Started] sample project into the directory you just created; for example:
```
git clone https://github.com/spring-guides/gs-spring-boot.git
```
1. Change directory to the completed project; for example:
```
cd gs-spring-boot
cd complete
```
1. Build the JAR file using Maven; for example:
```
mvn package
```
1. Once the web app has been created, change directory to the JAR file and start the web app; for example:
```
cd target
java -jar gs-spring-boot-0.1.0.jar
```
1. Test the web app by browsing to http://localhost:8080 using a web browser, or use the syntax like the following example if you have curl available:
```
curl http://localhost:8080
```
1. You should see the following message displayed: **Greetings from Spring Boot!**
![Browse Sample App][SB01]
## Create an Azure web app for use with Java
The following steps will walk you through the steps to create an Azure Web App, configure the required settings for Java, and configure your FTP credentials.
1. Browse to the [Azure portal] and log in.
1. Once you have logged into your account on the Azure portal, click the menu icon for **App Services**:
![Azure portal][AZ01]
1. When the **App Services** page is displayed, click **+ Add** to create a new App Service.
![Create App Service][AZ02]
1. When the list of web app templates is displayed, click the link for the basic Microsoft Web App.
![Web App Templates][AZ03]
1. When the information page for the Web App template is displayed, click **Create**.
![Create Web App][AZ04]
1. Provide a unique name for your web app and specify any additional settings, and then **Create**.
![Create Web App Settings][AZ05]
1. Once your web app has been created, click the menu icon for **App Services**, and then click your newly-created web app:
![List Web Apps][AZ06]
1. When your web app is displayed, specify the Java version by using the following steps:
a. Click the **Application Settings** menu item.
b. Choose **Java 8** for the Java version.
c. Choose **Newest** for the minor Java version.
d. Choose **Newest Tomcat 8.5** for the web container. (This container will not actually be used; Azure will use the container from your Spring Boot application.)
e. Click **Save**.
![Application Settings][AZ07]
1. Specify your FTP deployment credentials by using the following steps:
a. Click the **Deployment Credentials** menu item.
b. Specify your username and password.
c. Click **Save**.
![Specify Deployment Credentials][AZ08]
1. Retrieve your FTP connection information by using the following steps:
a. Click the **Deployment Credentials** menu item.
b. Copy your full FTP username and URL and save them for the next section of this tutorial.
![FTP URL and Credentials][AZ09]
## Deploy your Spring Boot web app to Azure
The following steps will walk you through the steps to deploy your Spring Boot web app to Azure.
1. Open a text editor such as Windows Notepad and paste the following text into a new document, then save the file as *web.config*:
```xml
<?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 &quot;%HOME%\site\wwwroot\gs-spring-boot-0.1.0.jar&quot;">
</httpPlatform>
</system.webServer>
</configuration>
```
1. After you have saved the *web.config* file to your system, connect to your web app via FTP using the URL, username, and password from the preceding section of this tutorial. For example:
```
ftp
open waws-prod-sn0-000.ftp.azurewebsites.windows.net
user wingtiptoys-springboot\wingtiptoysuser
pass ********
```
1. Change the remote directory to the root folder of your web app, (which is at */site/wwwroot*), then copy the JAR file from your Spring Boot application and the *web.config* from earlier. For example:
```
cd site/wwwroot
put gs-spring-boot-0.1.0.jar
put web.config
```
1. After you have deployed your JAR and *web.config* files to your web app, you need to restart your web app using the Azure portal:
![][AZ10]
1. Test the web app by browsing to your web app's URL using a web browser, or use the syntax like the following example if you have curl available:
```
curl http://wingtiptoys-springboot.azurewebsites.net/
```
1. You should see the following message displayed: **Greetings from Spring Boot!**
![Browse Sample App][SB02]
## Next steps
For more information about using Spring Boot applications on Azure, see the following articles:
* [Deploy a Spring Boot Application on Linux in the Azure Container Service](deploy-spring-boot-java-app-on-linux.md)
* [Deploy a Spring Boot Application on a Kubernetes Cluster in the Azure Container Service](deploy-spring-boot-java-app-on-kubernetes.md)
For more information about using Azure with Java, see the [Azure Java Developer Center] and the [Java Tools for Visual Studio Team Services].
For additional information about depoying web apps to Azure using FTP, see [Deploy your app to Azure App Service using FTP/S].
For further details about the Spring Boot sample project, see [Spring Boot Getting Started].
For help with getting started with your own Spring Boot applications, see the **Spring Initializr** at https://start.spring.io/.
For more information about configuring additional settings for your web app, see [Configure web apps in Azure App Service].
<!-- URL List -->
[Azure App Service]: https://azure.microsoft.com/services/app-service/
[Azure Container Service]: https://azure.microsoft.com/services/container-service/
[Azure Java Developer Center]: https://azure.microsoft.com/develop/java/
[Azure portal]: https://portal.azure.com/
[Configure web apps in Azure App Service]: /azure/app-service/web-sites-configure
[Deploy your app to Azure App Service using FTP/S]: https://docs.microsoft.com/azure/app-service/app-service-deploy-ftp
[free Azure account]: https://azure.microsoft.com/pricing/free-trial/
[Git]: https://github.com/
[Java Developer Kit (JDK)]: http://www.oracle.com/technetwork/java/javase/downloads/
[Java Tools for Visual Studio Team Services]: https://java.visualstudio.com/
[Maven]: http://maven.apache.org/
[MSDN subscriber benefits]: https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/
[Spring Boot]: http://projects.spring.io/spring-boot/
[Spring Boot Getting Started]: https://github.com/spring-guides/gs-spring-boot
[Spring Framework]: https://spring.io/
<!-- IMG List -->
[SB01]: ./media/deploy-spring-boot-java-web-app-on-azure/SB01.png
[SB02]: ./media/deploy-spring-boot-java-web-app-on-azure/SB02.png
[AZ01]: ./media/deploy-spring-boot-java-web-app-on-azure/AZ01.png
[AZ02]: ./media/deploy-spring-boot-java-web-app-on-azure/AZ02.png
[AZ03]: ./media/deploy-spring-boot-java-web-app-on-azure/AZ03.png
[AZ04]: ./media/deploy-spring-boot-java-web-app-on-azure/AZ04.png
[AZ05]: ./media/deploy-spring-boot-java-web-app-on-azure/AZ05.png
[AZ06]: ./media/deploy-spring-boot-java-web-app-on-azure/AZ06.png
[AZ07]: ./media/deploy-spring-boot-java-web-app-on-azure/AZ07.png
[AZ08]: ./media/deploy-spring-boot-java-web-app-on-azure/AZ08.png
[AZ09]: ./media/deploy-spring-boot-java-web-app-on-azure/AZ09.png
[AZ10]: ./media/deploy-spring-boot-java-web-app-on-azure/AZ10.png

Просмотреть файл

@ -0,0 +1,66 @@
### YamlMime:YamlDocument
documentType: LandingData
title: Spring Framework on Azure
metadata:
document_id:
title: Spring Framework on Azure
description: Get started using the Spring Framework on Microsoft Azure.
keywords: Azure, Java, Maven, Spring, Boot
author: rmcmurray
ms.author: robmcm
manager: routlaw
ms.date: 10/11/2017
ms.topic: article
ms.prod: azure
ms.technology: azure
ms.devlang: java
ms.service: multiple
sections:
- items:
- type: markdown
text: |
The [Spring Framework](http://spring.io/) is an open-source solution that helps Java developers create enterprise-level applications. One of the more-popular projects that is built on top of that platform is [Spring Boot](https://projects.spring.io/spring-boot/), which provides a simplified approach for creating stand-alone Java applications. Developers can combine these technologies with Microsoft Azure to create powerful, cloud-based applications.
To help developers get started with Spring Boot, several sample Spring Boot packages are available at <https://github.com/spring-guides/>. In addition to choosing from the list of basic Spring Boot projects, the **[Spring Initializr]** helps developers get started with creating custom Spring Boot applications.
- title: Get Started
items:
- type: paragraph
text: 'Get started developing apps using the Spring Framework with Microsoft Azure by using the following resources.'
- type: list
style: cards
className: cardsM
columns: 2
items:
- href: deploy-spring-boot-java-web-app-on-azure.md
html: <p>Deploy a Spring Boot Application to the Azure App Service</p>
image:
src: https://docs.microsoft.com/media/common/i_get-started.svg
title: Deploy a Spring Boot Application to the Azure App Service
- href: https://spring.io/
html: <p>Spring Framework</p>
image:
src: https://docs.microsoft.com/java/azure/spring-framework/media/index/i_spring_logo.png
title: Spring Framework
- title: Official Spring Documentation
items:
- type: list
style: cards
className: cardsM
columns: 2
items:
- href: https://spring.io/docs
html: <p>Learn Spring</p>
image:
src: https://docs.microsoft.com/media/common/i_reference.svg
title: Learn Spring
- href: https://spring.io/docs/reference
html: <p>Reference Documentation</p>
image:
src: https://docs.microsoft.com/media/common/i_api-reference.svg
title: Reference Documentation
- title: Samples
items:
- type: list
style: unordered
items:
- html: <a href="https://github.com/spring-guides/">Spring Guides </a>
- html: <a href="https://github.com/Microsoft/azure-spring-boot/">Spring Boot Starters for Azure</a>

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 43 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 79 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 50 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 23 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 49 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 28 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 32 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 64 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 131 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 1.7 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 6.0 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 32 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 43 KiB

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 74 KiB

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше