Skip to content

Commit e980f20

Browse files
authored
Merge pull request #276565 from cephalin/copilot
add try copilot
2 parents 4cac808 + 965c285 commit e980f20

File tree

2 files changed

+67
-6
lines changed

2 files changed

+67
-6
lines changed
43.8 KB
Loading

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

Lines changed: 67 additions & 6 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,6 +31,7 @@ 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

@@ -84,6 +86,12 @@ First, you set up a sample data-driven app as a starting point. For your conveni
8486
:::column-end:::
8587
:::row-end:::
8688

89+
> [!TIP]
90+
> You can ask [GitHub Copilot](https://docs.github.com/copilot/using-github-copilot/using-github-copilot-code-suggestions-in-your-editor) about this repository. For example:
91+
>
92+
> * *@workspace What does this project do?*
93+
> * *@workspace What does the .devcontainer folder do?*
94+
8795
Having issues? Check the [Troubleshooting section](#troubleshooting).
8896

8997
::: zone pivot="azure-portal"
@@ -242,7 +250,20 @@ Like the Tomcat convention, if you want to deploy to the root context of Tomcat,
242250
:::row-end:::
243251
:::row:::
244252
:::column span="2":::
245-
**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 response. 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):**
246267
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*.
247268
1. In the `contextIntialized()` method, find the commented code (lines 29-33) and uncomment it.
248269
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.
@@ -468,6 +489,26 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
468489

469490
## 5. Modify sample code and redeploy
470491

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 response. 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+
471512
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*.
472513

473514
1. In the `contextIntialized()` method, find the commented code (lines 29-33) and uncomment it.
@@ -488,10 +529,12 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
488529
azd deploy
489530
```
490531
491-
> [!TIP]
492-
> You can also just use `azd up` always, which does all of `azd package`, `azd provision`, and `azd deploy`.
493-
>
494-
> 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.
495538
496539
Having issues? Check the [Troubleshooting section](#troubleshooting).
497540
@@ -606,6 +649,24 @@ git push origin main
606649
607650
See [Set up GitHub Actions deployment from the Deployment Center](deploy-github-actions.md#set-up-github-actions-deployment-from-the-deployment-center).
608651
652+
#### What can I do with GitHub Copilot in my codespace?
653+
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).
655+
656+
A few tips for you when you talk to GitHub Copilot:
657+
658+
- In a single chat session, the questions and answers build on each other and you can adjust your questions to fine-tune the answer you get.
659+
- By default, GitHub Copilot doesn't have access to any file in your repository. You can ask it questions about a file, open the file in the editor first.
660+
- To let GitHub Copilot have access to all of the files in the repository when preparing its answers, begin your question 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 (with `@workspace`) even where to make the changes, but it's not allowed to make the changes for you. It's up to you to add the suggested changes and test it.
662+
663+
Here are some other things you can say to fine-tune the answer you get.
664+
665+
* Please change this code to use the data source jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS.
666+
* Some imports in your code are using javax but I have a Jakarta app.
667+
* 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.
669+
609670
## Next steps
610671
611672
- [Azure for Java Developers](/java/azure/)

0 commit comments

Comments
 (0)