Skip to content

Commit 5c66457

Browse files
author
Cephas Lin
committed
merge into mainline steps
1 parent b4c837d commit 5c66457

File tree

2 files changed

+53
-27
lines changed

2 files changed

+53
-27
lines changed
107 KB
Loading

articles/app-service/tutorial-java-tomcat-mysql-app.md

Lines changed: 53 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: cephalin
55
ms.author: cephalin
66
ms.devlang: java
77
ms.topic: tutorial
8-
ms.date: 05/08/2024
8+
ms.date: 05/31/2024
99
ms.custom: mvc, devx-track-extended-java, AppServiceConnectivity, devx-track-extended-azdevcli
1010
zone_pivot_groups: app-service-portal-azd
1111
---
@@ -22,6 +22,7 @@ This tutorial shows how to build, configure, and deploy a secure Tomcat applicat
2222

2323
* An Azure account with an active subscription. If you don't have an Azure account, you [can create one for free](https://azure.microsoft.com/free/java/).
2424
* Knowledge of Java with Tomcat development.
25+
* **(Optional)** To try GitHub Copilot, a [GitHub Copilot account](https://docs.github.com/copilot/using-github-copilot/using-github-copilot-code-suggestions-in-your-editor). A 30-day free trial is available.
2526

2627
::: zone-end
2728

@@ -30,12 +31,10 @@ This tutorial shows how to build, configure, and deploy a secure Tomcat applicat
3031
* An Azure account with an active subscription. If you don't have an Azure account, you [can create one for free](https://azure.microsoft.com/free/java).
3132
* [Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd) installed. You can follow the steps with the [Azure Cloud Shell](https://shell.azure.com) because it already has Azure Developer CLI installed.
3233
* Knowledge of Java with Tomcat development.
34+
* **(Optional)** To try GitHub Copilot, a [GitHub Copilot account](https://docs.github.com/copilot/using-github-copilot/using-github-copilot-code-suggestions-in-your-editor). A 30-day free trial is available.
3335

3436
::: zone-end
3537

36-
> [!TIP]
37-
> To try GitHub Copilot, you need a [GitHub Copilot account](https://docs.github.com/copilot/using-github-copilot/using-github-copilot-code-suggestions-in-your-editor). A 30-day free trial is available.
38-
3938
## Skip to the end
4039

4140
You can quickly deploy the sample app in this tutorial and see it running in Azure. Just run the following commands in the [Azure Cloud Shell](https://shell.azure.com), and follow the prompt:
@@ -216,9 +215,6 @@ In this step, you configure GitHub deployment using GitHub Actions. It's just on
216215

217216
Like the Tomcat convention, if you want to deploy to the root context of Tomcat, name your built artifact *ROOT.war*.
218217

219-
> [!TIP]
220-
> In **Step 4**, try [letting GitHub Copilot show you the code changes to make](#make-code-changes-using-github-copilot).
221-
222218
:::row:::
223219
:::column span="2":::
224220
**Step 1:** Back in the App Service page, in the left menu, select **Deployment Center**.
@@ -254,7 +250,20 @@ Like the Tomcat convention, if you want to deploy to the root context of Tomcat,
254250
:::row-end:::
255251
:::row:::
256252
:::column span="2":::
257-
**Step 4:**
253+
**Step 4 (Option 1: with GitHub Copilot):**
254+
1. Start a new chat session by clicking the **Chat** view, then clicking **+**.
255+
1. Ask, "*@workspace How does the app connect to the database?*". Copilot might give you some explanation about the `jdbc/MYSQLDS` data source and how it's configured.
256+
1. Ask, "*@workspace I want to replace the data source defined in persistence.xml with an existing JNDI data source in Tomcat but I want to do it dynamically.*". Copilot might give you a code suggestion similar to the one in the **Option 2: without GitHub Copilot** steps below and even tell you to make the change in the [ContextListener](https://github.com/Azure-Samples/msdocs-tomcat-mysql-sample-app/blob/starter-no-infra/src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java) class.
257+
1. Open *src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java* in the explorer and add the code suggestion in the `contextInitialized` method.
258+
GitHub Copilot doesn't give you the same response every time, you might need to add additional questions to fine-tune its reponse. For tips, see [What can I do with GitHub Copilot in my codespace?](#what-can-i-do-with-github-copilot-in-my-codespace)
259+
:::column-end:::
260+
:::column:::
261+
:::image type="content" source="media/tutorial-java-tomcat-mysql-app/github-copilot-1.png" alt-text="A screenshot showing how to ask a question in a new GitHub Copilot chat session." lightbox="media/tutorial-java-tomcat-mysql-app/github-copilot-1.png":::
262+
:::column-end:::
263+
:::row-end:::
264+
:::row:::
265+
:::column span="2":::
266+
**Step 4 (Option 2: without GitHub Copilot):**
258267
1. Open *src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java* in the explorer. When the application starts, this class loads the database settings in *src/main/resources/META-INF/persistence.xml*.
259268
1. In the `contextIntialized()` method, find the commented code (lines 29-33) and uncomment it.
260269
This code checks to see if the `AZURE_MYSQL_CONNECTIONSTRING` app setting exists, and changes the data source to `java:comp/env/jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS`, which is the data source you found earlier in *context.xml* in the SSH shell.
@@ -480,6 +489,26 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
480489

481490
## 5. Modify sample code and redeploy
482491

492+
# [With GitHub Copilot](#tab/copilot)
493+
494+
1. Back in the GitHub codespace of your sample fork, start a new chat session by clicking the **Chat** view, then clicking **+**.
495+
496+
1. Ask, "*@workspace How does the app connect to the database?*". Copilot might give you some explanation about the `jdbc/MYSQLDS` data source and how it's configured.
497+
498+
1. Ask, "*@workspace I want to replace the data source defined in persistence.xml with an existing JNDI data source in Tomcat but I want to do it dynamically.*". Copilot might give you a code suggestion similar to the one in the **Option 2: without GitHub Copilot** steps below and even tell you to make the change in the [ContextListener](https://github.com/Azure-Samples/msdocs-tomcat-mysql-sample-app/blob/starter-no-infra/src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java) class.
499+
500+
1. Open *src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java* in the explorer and add the code suggestion in the `contextInitialized` method.
501+
502+
GitHub Copilot doesn't give you the same response every time, you might need to add additional questions to fine-tune its reponse. For tips, see [What can I do with GitHub Copilot in my codespace?](#what-can-i-do-with-github-copilot-in-my-codespace)
503+
504+
1. Back in the codespace terminal, run `azd deploy`.
505+
506+
```bash
507+
azd deploy
508+
```
509+
510+
# [Without GitHub Copilot](#tab/nocopilot)
511+
483512
1. Back in the GitHub codespace of your sample fork, from the explorer, open *src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java*. When the application starts, this class loads the database settings in *src/main/resources/META-INF/persistence.xml*.
484513

485514
1. In the `contextIntialized()` method, find the commented code (lines 29-33) and uncomment it.
@@ -494,19 +523,18 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
494523
495524
This code checks to see if the `AZURE_MYSQL_CONNECTIONSTRING` app setting exists, and changes the data source to `java:comp/env/jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS`, which is the data source you found earlier in *context.xml* in the SSH shell.
496525
497-
> [!TIP]
498-
> Try [letting GitHub Copilot show you the code changes to make](#make-code-changes-using-github-copilot).
499-
500526
1. Back in the codespace terminal, run `azd deploy`.
501527
502528
```bash
503529
azd deploy
504530
```
505531
506-
> [!TIP]
507-
> You can also just use `azd up` always, which does all of `azd package`, `azd provision`, and `azd deploy`.
508-
>
509-
> To find out how the War file is packaged, you can run `azd package --debug` by itself.
532+
-----
533+
534+
> [!TIP]
535+
> You can also just use `azd up` always, which does all of `azd package`, `azd provision`, and `azd deploy`.
536+
>
537+
> To find out how the War file is packaged, you can run `azd package --debug` by itself.
510538
511539
Having issues? Check the [Troubleshooting section](#troubleshooting).
512540
@@ -621,25 +649,23 @@ git push origin main
621649
622650
See [Set up GitHub Actions deployment from the Deployment Center](deploy-github-actions.md#set-up-github-actions-deployment-from-the-deployment-center).
623651
624-
#### Make code changes using GitHub Copilot
625-
626-
With a [GitHub Copilot account](https://docs.github.com/copilot/using-github-copilot/using-github-copilot-code-suggestions-in-your-editor) (30-day free trial available), you can make the code changes in this tutorial by using Copilot Chat in the codespace. Since GitHub Copilot doesn't give you the same answer every time, the following is just an example:
627-
628-
1. In your [codespace](#1-run-the-sample), start a new Copilot chat session in the **Chat** view. The GitHub Copilot chat extension was installed by the container definition (see *.devcontainer/devcontainer.json*).
629-
630-
1. Ask, "*@workspace How does the app connect to the database?*"
652+
#### What can I do with GitHub Copilot in my codespace?
631653
632-
Copilot might give you some explanation about the `jdbc/MYSQLDS` data source and how it's configured. For the `@workspace` agent, see [Use the @workspace agent](https://github.blog/2024-03-25-how-to-use-github-copilot-in-your-ide-tips-tricks-and-best-practices/#10-use-the-workspace-agent).
654+
You might have noticed that the GitHub Copilot chat view was already there for you when you created the codespace. For your convenience, we include the GitHub Copilot chat extension in the container definition (see *.devcontainer/devcontainer.json*). However, you need a [GitHub Copilot account](https://docs.github.com/copilot/using-github-copilot/using-github-copilot-code-suggestions-in-your-editor) (30-day free trial available).
633655
634-
1. Ask, "*@workspace I want to replace the data source defined in persistence.xml with an existing JNDI data source in Tomcat but I want to do it dynamically.*"
656+
A few tips for you when you talk to GitHub Copilot:
635657
636-
Copilot might show you sample code similar to [the one in this tutorial](#5-deploy-sample-code) and even tell you to make the change in the [ContextListener](https://github.com/Azure-Samples/msdocs-tomcat-mysql-sample-app/blob/starter-no-infra/src/main/java/com/microsoft/azure/appservice/examples/tomcatmysql/ContextListener.java) class. However, it won't make the actual change for you. It's up to you to add the suggested code and test it.
658+
- In a single chat session, the questions and answers build on each other and you can get Gi
659+
- You can ask GitHub Copilot about a file that you already opened in the editor.
660+
- To let GitHub Copilot access all of the files in the repository when formulating its answers, start your sentence with `@workspace`. For more information, see [Use the @workspace agent](https://github.blog/2024-03-25-how-to-use-github-copilot-in-your-ide-tips-tricks-and-best-practices/#10-use-the-workspace-agent).
661+
- In the chat session, GitHub Copilot can suggest changes and (if you start your sentence with `@workspace`) even where to make the changes, but it can't make the changes for you. It's up to you to add the suggested code and test it.
637662
638-
Here are some other things you can say to fine-tune the answer you get.
663+
Here are some other things you can say to fine-tune the response you get.
639664
640665
* Please change this code to use the data source jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS.
641-
* Some imports in this are using javax but I have a Jakarta app.
666+
* Some imports in your code are using javax but I have a Jakarta app.
642667
* I want this code to run only if the environment variable AZURE_MYSQL_CONNECTIONSTRING is set.
668+
* I want this code to run only in Azure App Service and not locally.
643669
644670
## Next steps
645671

0 commit comments

Comments
 (0)