{"id":18736776,"url":"https://github.com/selvasingh/e2e-java-experience-in-app-service-linux-part-2","last_synced_at":"2025-04-12T19:31:53.610Z","repository":{"id":82967569,"uuid":"155127902","full_name":"selvasingh/e2e-java-experience-in-app-service-linux-part-2","owner":"selvasingh","description":" Deploy Spring Boot app to Java SE - end-to-end Java experience in App Service Linux","archived":false,"fork":false,"pushed_at":"2018-10-29T00:05:50.000Z","size":216,"stargazers_count":0,"open_issues_count":0,"forks_count":18,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T14:01:42.435Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"Azure-Samples/e2e-java-experience-in-app-service-linux-part-2","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/selvasingh.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-10-29T00:04:09.000Z","updated_at":"2023-09-28T21:19:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"7614e14a-4e3e-456c-aa40-9a7f1f35d86b","html_url":"https://github.com/selvasingh/e2e-java-experience-in-app-service-linux-part-2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selvasingh%2Fe2e-java-experience-in-app-service-linux-part-2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selvasingh%2Fe2e-java-experience-in-app-service-linux-part-2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selvasingh%2Fe2e-java-experience-in-app-service-linux-part-2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/selvasingh%2Fe2e-java-experience-in-app-service-linux-part-2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/selvasingh","download_url":"https://codeload.github.com/selvasingh/e2e-java-experience-in-app-service-linux-part-2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248621147,"owners_count":21134758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T15:22:25.800Z","updated_at":"2025-04-12T19:31:53.604Z","avatar_url":"https://github.com/selvasingh.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\nservices: app-service, cosmos-db\nplatforms: java\nauthor: selvasingh\n---\n\n# End-to-end Java Experience in App Service Linux \n\nThis guide walks you through the process of building, \nconfiguring, deploying, trouble shooting and scaling \nJava Web apps in App Service Linux. \n\n## What you will build\n\nYou will build a Java Web app using \n[Spring Boot](https://spring.io/projects/spring-boot), \n[Spring Data for Cosmos DB](https://docs.microsoft.com/en-us/java/azure/spring-framework/configure-spring-boot-starter-java-app-with-cosmos-db?view=azure-java-stable), \n[Azure Cosmos DB](https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-introduction)\nand\n[App Service Linux](https://docs.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro).\n\n## What you will need\n\nIn order to deploy a Java Web app to cloud, you need \nan Azure subscription. If you do not already have an Azure \nsubscription, you can activate your \n[MSDN subscriber benefits](https://azure.microsoft.com/pricing/member-offers/msdn-benefits-details/) \nor sign up for a \n[free Azure account]((https://azure.microsoft.com/pricing/free-trial/)).\n\nIn addition, you will need the following:\n\n| [Azure CLI](http://docs.microsoft.com/cli/azure/overview) \n| [Java 8](https://www.azul.com/downloads/azure-only/zulu) \n| [Maven 3](http://maven.apache.org/) \n| [Git](https://github.com/) \n| \n\n## Getting Started\n\nYou can start from scratch and complete each step, or \nyou can bypass basic setup steps that you are already \nfamiliar with. Either way, you will end up with working code.\n\nWhen you are finished, you can check your results \nagainst YOUR code in \n[e2e-java-experience-in-app-service-linux-part-2/complete](https://github.com/Azure-Samples/e2e-java-experience-in-app-service-linux-part-2/tree/master/complete).\n\nYou can start from [e2e-java-experience-in-app-service-linux-part-2/initial](https://github.com/Azure-Samples/e2e-java-experience-in-app-service-linux-part-2/tree/master/initial).\nOr, you can clone from [spring-todo-app](https://github.com/microsoft/spring-todo-app) \n\nIf you are starting from scratch, you can scaffold a Web app using \n[Maven Web app archetype](https://maven.apache.org/archetypes/maven-archetype-webapp/)\nor [start.spring.io](https://start.spring.io/).\n\n#### Step ONE - Clone and Prep\n\n```bash\ngit clone --recurse-submodules https://github.com/Azure-Samples/e2e-java-experience-in-app-service-linux-part-2.git\nyes | cp -rf .prep/* .\n```\n\n## Create Azure Cosmos DB\n\nCreate Azure Cosmos DB \nusing [Azure CLI 2.0](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest) \n\n### STEP A - LOGIN to Azure\nLogin your Azure CLI, and set your subscription \n    \n```bash\naz login\naz account set -s \u003cyour-subscription-id\u003e\n```\n### STEP B - Create Resource Group\n\nCreate an Azure Resource Group, and note down the resource group name\n\n```bash\naz group create -n \u003cyour-azure-group-name\u003e \\\n    -l \u003cyour-resource-group-region\u003e\n```\n\n### STEP C - Create COSMOS DB\n\nCreate Azure Cosmos DB with GlobalDocumentDB kind. \nThe name of Cosmos DB must use only lower case letters. Note down the `documentEndpoint` field in the response\n\n```bash\naz cosmosdb create --kind GlobalDocumentDB \\\n    -g \u003cyour-azure-group-name\u003e \\\n    -n \u003cyour-azure-COSMOS-DB-name-in-lower-case-letters\u003e\n```\n\n### STEP D - Get COSMOS DB Key\n\nGet your Azure Cosmos DB key, get the `primaryMasterKey`\n\n```bash\naz cosmosdb list-keys -g \u003cyour-azure-group-name\u003e -n \u003cyour-azure-COSMOSDB-name\u003e\n```\n\n## Build and Run Locally - Spring TODO App Powered Using Azure Cosmos DB\n\nOpen the [initial/spring-todo-app](https://github.com/Azure-Samples/e2e-java-experience-in-app-service-linux-part-2/tree/master/initial)\nsample app in your favorite IDE - IntelliJ | Eclipse | VS Code.\n\n### STEP 1 - Change directory\n\n```bash\ncd initial/spring-todo-app\n```  \n    \n### STEP 2 - Configure the app\n\nSet environment variables using a script file. Start with \nthe supplied template in the repo: \n\n```bash\ncp set-env-variables-template.sh .scripts/set-env-variables.sh\n```\n \nEdit .scripts/set-env-variables.sh and supply Azure \nCosmos DB connection info. Particularly:\n\n```bash\nexport COSMOSDB_URI=\u003cput-your-COSMOS-DB-documentEndpoint-URI-here\u003e\nexport COSMOSDB_KEY=\u003cput-your-COSMOS-DB-primaryMasterKey-here\u003e\nexport COSMOSDB_DBNAME=\u003cput-your-COSMOS-DB-name-here\u003e\n\n// App Service Linux Configuration\nexport RESOURCEGROUP_NAME=\u003cput-your-resource-group-name-here\u003e\nexport WEBAPP_NAME=\u003cput-your-Webapp-name-here\u003e\nexport REGION=\u003cput-your-REGION-here\u003e\n```\n   \nSet environment variables:\n\n```bash\nsource .scripts/set-env-variables.sh\n```\n\n### STEP 3 - Run Spring TODO App locally\n\n```bash\nmvn package spring-boot:run\n```\n\n   ```bash\nbash-3.2$ mvn package spring-boot:run\n[INFO] Scanning for projects...\n[INFO] \n[INFO] ------------------------------------------------------------------------\n[INFO] Building spring-todo-app 2.0-SNAPSHOT\n[INFO] ------------------------------------------------------------------------\n[INFO] \n\n\n[INFO] SimpleUrlHandlerMapping - Mapped URL path [/webjars/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]\n[INFO] SimpleUrlHandlerMapping - Mapped URL path [/**] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]\n[INFO] WelcomePageHandlerMapping - Adding welcome page: class path resource [static/index.html]\n2018-10-28 15:04:32.101  INFO 7673 --- [           main] c.m.azure.documentdb.DocumentClient      : Initializing DocumentClient with serviceEndpoint [https://asir-cosmosdb-01-19-2008-westus.documents.azure.com:443/], ConnectionPolicy [ConnectionPolicy [requestTimeout=60, mediaRequestTimeout=300, connectionMode=Gateway, mediaReadMode=Buffered, maxPoolSize=800, idleConnectionTimeout=60, userAgentSuffix=;spring-data/2.0.6;098063be661ab767976bd5a2ec350e978faba99348207e8627375e8033277cb2, retryOptions=com.microsoft.azure.documentdb.RetryOptions@6b9fb84d, enableEndpointDiscovery=true, preferredLocations=null]], ConsistencyLevel [null]\n[INFO] AnnotationMBeanExporter - Registering beans for JMX exposure on startup\n[INFO] TomcatWebServer - Tomcat started on port(s): 8080 (http) with context path ''\n[INFO] TodoApplication - Started TodoApplication in 45.573 seconds (JVM running for 76.534)\n   ```\n\nYou can access Spring TODO App here: [http://localhost:8080/](http://localhost:8080/).\n    \n![](./media/spring-todo-app-running-locally.jpg)\n\n## Deploy to App Service Linux \n\n### Step 4 - Configure for Cloud Deployment\n\nAdd [Maven Plugin for Azure App Service](https://github.com/Microsoft/azure-maven-plugins/blob/develop/azure-webapp-maven-plugin/README.md) configuration to POM.xml and deploy\nSpring TODO App to Java SE in App Service Linux:\n\n```xml    \n\u003cplugins\u003e \n\n    \u003c!--*************************************************--\u003e\n    \u003c!-- Deploy to Java SE in App Service Linux           --\u003e\n    \u003c!--*************************************************--\u003e\n       \n    \u003cplugin\u003e\n        \u003cgroupId\u003ecom.microsoft.azure\u003c/groupId\u003e\n            \u003cartifactId\u003eazure-webapp-maven-plugin\u003c/artifactId\u003e\n            \u003cversion\u003e1.4.0\u003c/version\u003e\n            \u003cconfiguration\u003e\n            \u003cdeploymentType\u003ejar\u003c/deploymentType\u003e\n            \n            \u003c!-- Web App information --\u003e\n            \u003cresourceGroup\u003e${RESOURCEGROUP_NAME}\u003c/resourceGroup\u003e\n            \u003cappName\u003e${WEBAPP_NAME}\u003c/appName\u003e\n            \u003cregion\u003e${REGION}\u003c/region\u003e\n            \n            \u003c!-- Java Runtime Stack for Web App on Linux--\u003e\n            \u003clinuxRuntime\u003ejre8\u003c/linuxRuntime\u003e\n            \n            \u003cappSettings\u003e\n                \u003cproperty\u003e\n                    \u003cname\u003eCOSMOSDB_URI\u003c/name\u003e\n                    \u003cvalue\u003e${COSMOSDB_URI}\u003c/value\u003e\n                \u003c/property\u003e\n                \u003cproperty\u003e\n                    \u003cname\u003eCOSMOSDB_KEY\u003c/name\u003e\n                    \u003cvalue\u003e${COSMOSDB_KEY}\u003c/value\u003e\n                \u003c/property\u003e\n                \u003cproperty\u003e\n                    \u003cname\u003eCOSMOSDB_DBNAME\u003c/name\u003e\n                    \u003cvalue\u003e${COSMOSDB_DBNAME}\u003c/value\u003e\n                \u003c/property\u003e\n                \u003cproperty\u003e\n                    \u003cname\u003eJAVA_OPTS\u003c/name\u003e\n                    \u003cvalue\u003e-Dserver.port=80\u003c/value\u003e\n                \u003c/property\u003e\n            \u003c/appSettings\u003e\n            \n        \u003c/configuration\u003e\n    \u003c/plugin\u003e            \n    ...\n\u003c/plugins\u003e\n```\n\n### Step 5 - Deploy to Java SE in App Service Linux\n\n```bash\n\n// Deploy\nbash-3.2$ mvn azure-webapp:deploy\n[INFO] Scanning for projects...\n[INFO] \n[INFO] ------------------------------------------------------------------------\n[INFO] Building spring-todo-app 2.0-SNAPSHOT\n[INFO] ------------------------------------------------------------------------\n[INFO] \n[INFO] --- azure-webapp-maven-plugin:1.4.0:deploy (default-cli) @ spring-todo-app ---\n[INFO] Authenticate with Azure CLI 2.0\n[INFO] Target Web App doesn't exist. Creating a new one...\n[INFO] Creating App Service Plan 'ServicePlanb6ba8178-5bbb-49e7'...\n[INFO] Successfully created App Service Plan.\n[INFO] Successfully created Web App.\n[INFO] Trying to deploy artifact to spring-todo-app...\n[INFO] Successfully deployed the artifact to https://spring-todo-app.azurewebsites.net\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time: 02:19 min\n[INFO] Finished at: 2018-10-28T15:32:03-07:00\n[INFO] Final Memory: 50M/574M\n[INFO] ------------------------------------------------------------------------\n```\n\n#### Open Spring Boot TODO App running on Java SE in App Service Linux\n\n```bash\nopen https://spring-todo-app.azurewebsites.net\n```\n![](./media/spring-todo-app-running-in-app-service.jpg)\n\n\n### Step 6 - Trouble Shoot Spring TODO App on Azure by Viewing Logs\n\nConfigure logs for the deployed Java Web \napp in App Service Linux:\n\n```bash\naz webapp log config --name ${WEBAPP_NAME} \\\n --resource-group ${RESOURCEGROUP_NAME} \\\n  --web-server-logging filesystem\n```\n\nOpen Java Web app remote log stream from a local machine:\n\n```bash\naz webapp log tail --name ${WEBAPP_NAME} \\\n --resource-group ${RESOURCEGROUP_NAME}\n \nbash-3.2$ az webapp log tail --name ${WEBAPP_NAME}  --resource-group ${RESOURCEGROUP_NAME}\n2018-10-28T22:50:17  Welcome, you are now connected to log-streaming service.\n2018-10-28T22:44:56.265890407Z   _____                               \n2018-10-28T22:44:56.265930308Z   /  _  \\ __________ _________   ____  \n2018-10-28T22:44:56.265936008Z  /  /_\\  \\___   /  |  \\_  __ \\_/ __ \\ \n2018-10-28T22:44:56.265940308Z /    |    \\/    /|  |  /|  | \\/\\  ___/ \n2018-10-28T22:44:56.265944408Z \\____|__  /_____ \\____/ |__|    \\___  \u003e\n2018-10-28T22:44:56.265948508Z         \\/      \\/                  \\/ \n2018-10-28T22:44:56.265952508Z A P P   S E R V I C E   O N   L I N U X\n2018-10-28T22:44:56.265956408Z Documentation: http://aka.ms/webapp-linux\n2018-10-28T22:44:56.266260910Z Setup openrc ...\n2018-10-28T22:44:57.396926506Z Service `hwdrivers' needs non existent service `dev'\n2018-10-28T22:44:57.397294409Z  * Caching service dependencies ... [ ok ]\n2018-10-28T22:44:57.474152273Z Starting ssh service...\n...\n...\n2018-10-28T22:46:13.432160734Z [INFO] AnnotationMBeanExporter - Registering beans for JMX exposure on startup\n2018-10-28T22:46:13.744859424Z [INFO] TomcatWebServer - Tomcat started on port(s): 80 (http) with context path ''\n2018-10-28T22:46:13.783230205Z [INFO] TodoApplication - Started TodoApplication in 57.209 seconds (JVM running for 70.815)\n2018-10-28T22:46:14.887366993Z 2018-10-28 22:46:14.887  INFO 198 --- [p-nio-80-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'\n2018-10-28T22:46:14.887637695Z [INFO] DispatcherServlet - FrameworkServlet 'dispatcherServlet': initialization started\n2018-10-28T22:46:14.998479907Z [INFO] DispatcherServlet - FrameworkServlet 'dispatcherServlet': initialization completed in 111 ms\n\n2018-10-28T22:49:20.572059062Z Sun Oct 28 22:49:20 GMT 2018 GET ======= /api/todolist =======\n2018-10-28T22:49:25.850543080Z Sun Oct 28 22:49:25 GMT 2018 DELETE ======= /api/todolist/{4f41ab03-1b12-4131-a920-fe5dfec106ca} ======= \n2018-10-28T22:49:26.047126614Z Sun Oct 28 22:49:26 GMT 2018 GET ======= /api/todolist =======\n2018-10-28T22:49:30.201740227Z Sun Oct 28 22:49:30 GMT 2018 POST ======= /api/todolist ======= Milk\n2018-10-28T22:49:30.413468872Z Sun Oct 28 22:49:30 GMT 2018 GET ======= /api/todolist =======\n\n\n```\n\nWhen you are finished, you can check your results \nagainst YOUR code in \n[e2e-java-experience-in-app-service-linux-part-2/complete](https://github.com/Azure-Samples/e2e-java-experience-in-app-service-linux-part-2/tree/master/complete).\n\n## Scale out the Spring TODO App\n\nScale out Java Web app using Azure CLI:\n\n```bash\naz appservice plan update --number-of-workers 2 \\\n   --name ${WEBAPP_PLAN_NAME} \\\n   --resource-group ${RESOURCEGROUP_NAME}\n```\n\n## Congratulations!\n\nCongratulations!! You built and scaled out a Java Web app using \n[Spring Boot](https://spring.io/projects/spring-boot), \n[Spring Data for Cosmos DB](https://docs.microsoft.com/en-us/java/azure/spring-framework/configure-spring-boot-starter-java-app-with-cosmos-db?view=azure-java-stable), \n[Azure Cosmos DB](https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-introduction)\nand\n[App Service Linux](https://docs.microsoft.com/en-us/azure/app-service/containers/app-service-linux-intro).\n.\n\n## Resources\n\n- [Java in App Service Linux dev guide](https://docs.microsoft.com/en-us/azure/app-service/containers/app-service-linux-java)\n- [Azure for Java Developers](https://docs.microsoft.com/en-us/java/azure/)\n\n---\n\nThis project has adopted \nthe [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). \nFor more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or \ncontact [opencode@microsoft.com](mailto:opencode@microsoft.com) \nwith any additional \nquestions or comments.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselvasingh%2Fe2e-java-experience-in-app-service-linux-part-2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fselvasingh%2Fe2e-java-experience-in-app-service-linux-part-2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fselvasingh%2Fe2e-java-experience-in-app-service-linux-part-2/lists"}