Skip to content

Commit

Permalink
Merge pull request #217 from MicrosoftDocs/master
Browse files Browse the repository at this point in the history
11/15 AM Publish
  • Loading branch information
huypub authored Nov 15, 2019
2 parents 25cef39 + 08149f0 commit 54d3455
Show file tree
Hide file tree
Showing 35 changed files with 168 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ ms.author: brendm
ms.reviewer: joshuapa
ms.date: 4/24/2019
ms.devlang: java
ms.service: app-service, cosmos-db
ms.service: cosmos-db
ms.topic: article
---

# How to use Spring and Cosmos DB with App Service on Linux

## Overview

This article will walk you through the process of building, configuring, deploying, troubleshooting, and scaling Java Web apps in Azure App Service on Linux.

It will demonstrate the usage of the following components:
Expand All @@ -33,6 +31,7 @@ The following prerequisites are required in order to follow the steps in this ar
- [Maven 3](http://maven.apache.org/)

## Clone the Sample Java Web App Repository

For this exercise you'll be using the Spring Todo app, which is a Java application built using [Spring Boot](https://spring.io/projects/spring-boot), [Spring Data for Cosmos DB](https://docs.microsoft.com/azure/java/spring-framework/configure-spring-boot-starter-java-app-with-cosmos-db) and [Azure Cosmos DB](https://docs.microsoft.com/azure/cosmos-db/sql-api-introduction).
1. Clone the Spring Todo app and copy the contents of the **.prep** folder to initialize the project:

Expand All @@ -53,16 +52,20 @@ For this exercise you'll be using the Spring Todo app, which is a Java applicati

```bash
cd initial\spring-todo-app
```
```

## Create an Azure Cosmos DB from Azure CLI

The following procedure creates Azure Cosmos database using CLI.

1. Login to your Azure CLI, and set your subscription id.

```bash
az login
```

2. Set the subscription id if needed.

```bash
az account set -s <your-subscription-id>
```
Expand All @@ -83,14 +86,16 @@ The name of the Cosmos DB must use only lower case letters. Make sure to note th
-n <your-azure-COSMOS-DB-name-in-lower-case-letters>
```
4. Get your Azure Cosmos DB keys, record the `primaryMasterKey` value for later use.
5. Get your Azure Cosmos DB keys, record the `primaryMasterKey` value for later use.
```bash
az cosmosdb list-keys -g <your-azure-group-name> -n <your-azure-COSMOSDB-name>
az cosmosdb keys list -g <your-azure-group-name> -n <your-azure-COSMOSDB-name>
```
## Build and Run the App Locally
The following procedure runs the application on the development computer.
1. Within your console of choice configure the environment variables shown in the following code sections with the Azure and Cosmos DB connection information you gathered previously in this article. You'll need to provide a unique name for **WEBAPP_NAME** and value for the **REGION** variables.

For Linux (Bash):
Expand Down Expand Up @@ -135,6 +140,8 @@ set REGION=<put-your-REGION-here>
## Deploy to App Service Linux
The following procedure deploys the application to Linux on Azure.
1. Open the pom.xml file that you previously copied to the **initial/spring-todo-app** directory of the repository. Ensure that the [Maven Plugin for Azure App Service](https://github.com/Microsoft/azure-maven-plugins/blob/develop/azure-webapp-maven-plugin/README.md) is included as seen in the pom.xml file below. If the version is not set to **1.6.0** then update the value.
```xml
Expand Down Expand Up @@ -226,6 +233,8 @@ bash-3.2$ mvn azure-webapp:deploy
## Troubleshoot Spring Todo App on Azure by Viewing Logs
The following procedure opens log files on Azure.
1. Configure logs for the deployed Java Web app in Azure App Service in Linux:
```bash
Expand Down Expand Up @@ -279,6 +288,8 @@ bash-3.2$ az webapp log tail --name ${WEBAPP_NAME} --resource-group ${RESOURCEG
## Scale out the Spring Todo App
Use the following procedure to scale the application.
1. Scale out Java Web app using Azure CLI:
```bash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,12 @@ description: Configure a Spring Boot application created with Spring Initializr
services: Application-Insights
documentationcenter: java
author: dhaval24
manager: alexklim
editor: ''
ms.assetid:
ms.author: dhdoshi
ms.date: 12/19/2018
ms.date: 11/29/2019
ms.devlang: java
ms.service: azure-monitor
ms.tgt_pltfrm: application-insights
ms.topic: article
ms.workload: na
---

# Configure a Spring Boot Initializer app to use Application Insights
Expand All @@ -31,6 +27,8 @@ The following prerequisites are required in order to complete the steps in this

## Create a custom application using Spring Initializr

Create an application with the following procedure.

1. Browse to [https://start.spring.io/](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 select web dependency in the dependencies section.
Expand All @@ -39,45 +37,46 @@ The following prerequisites are required in order to complete the steps in this

> [!NOTE]
>
> Spring Initializr will use the **Group** and **Artifact** names to create the package name; for example: *com.example.demo*.
> Spring Initializr will use the **Group** and **Artifact** names to create the package name; for example: *com.vged.appinsights*.
>
1. Click the button to **Generate Project**.
1. Click the **Generate** button.

1. When prompted, download the project to a path on your local computer.

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][SI02]

## Create an Application Insights Resource on Azure

1. Browse to Azure at <https://portal.azure.com/> and click **+New**.

![Azure][AZ01]
Create an application insights resource using the following procedure.

1. Click **Management Tools**, and then click **Application Insights**.
1. Browse to Azure at <https://portal.azure.com/> and click **+ Create a new resource**.

![Azure][AZ02]
1. Click **IT & Management Tools**, and then click **Application Insights**.

1. On the **New Application Insights Resource** page, specify the following information:
1. On the **New Application Insights Resource** page, enter the following information:

* Enter the **Name** for your Application Insights resource.
* Choose the **Application Type** to Java Web Application.
* Specify your **Subscription**, **Resource group** and **Location**.
* Select Pin to dashboard option, if you would like to pin the resource on your Azure.
* Specify your **Subscription** and **Resource group**.
* Enter the **Name** for your Application Insights resource.
* Select **Region**.

When you have specified these options, click **Create** to create your Application Insights resource.
When you have specified these options, click **Review and create**.

![Azure][AZ03]

1. Once your resource has been created, you will see it listed on your Azure **Dashboard**, as well as under the **All Resources** pages. You can click on your resource on any of those locations to open the overview page of the Application Insights resource. From this overview page please copy the **instrumentation key**.

* Review the specifications, and click **Create**.

After your resource has been created, you will see it listed on your Azure **Dashboard**, as well as under the **All Resources** pages. You can click on your resource on any of those locations to open the overview page of the Application Insights resource.

From the overview page copy the **instrumentation key**.

![Azure][AZ04]

## Configure your downloaded Spring Boot Application to use Application Insights

1. Locate the *POM.xml* file in the root directory of your app, and add the following dependency in its dependencies section.
Configure the application using the following procedure.

1. Locate the *POM.xml* file in the root directory of your app, and add the following dependency in its dependencies section.

```XML
<dependency>
Expand All @@ -89,8 +88,6 @@ The following prerequisites are required in order to complete the steps in this

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 with appropriate credentials:

```yaml
Expand Down Expand Up @@ -186,6 +183,8 @@ Click on the **Application Map** tile to view high-level components and their in

## Configure Springboot Application to send log4j logs to Application Insights

Configure the application to send logs using the following procedure.

1. Modify the POM.xml file of the project and add/modify the dependencies section with following.

```xml
Expand Down Expand Up @@ -253,13 +252,10 @@ Click on the **Application Map** tile to view high-level components and their in
</Loggers>
</Configuration>
```
4. Build and run the Spring Boot application again as shown above.

Within a few seconds, you should see all the spring logs being available on Azure.

![Azure][AZ06]
4. Build and run the Spring Boot application again as shown above.

You can even look at the detailed log messages and do analysis on Analytics Portal.
Within a few seconds, you should see all the spring logs being available on Azure. You can look at the detailed log messages and do analysis on Analytics Portal.

![Azure][AZ07]

Expand Down Expand Up @@ -313,7 +309,7 @@ The **[Spring Framework]** is an open-source solution that helps Java developers
[AZ07]: ./media/configure-spring-boot-starter-java-app-with-azure-application-insights/traces_details.png
[AZ08]: ./media/configure-spring-boot-starter-java-app-with-azure-application-insights/AppMap.png

[SI01]: ./media/configure-spring-boot-starter-java-app-with-azure-application-insights/spring_start.png
[SI01]: ./media/configure-spring-boot-starter-java-app-with-azure-application-insights/spring_start.PNG
[SI02]: ./media/configure-spring-boot-starter-java-app-with-azure-application-insights/After_extract.png

[RE01]: ./media/configure-spring-boot-starter-java-app-with-azure-application-insights/applicationproperties_loc.png
Expand Down
Loading

0 comments on commit 54d3455

Please sign in to comment.