Giter Club home page Giter Club logo

todo-app-java-on-azure's Introduction

Todo App Java On Azure

This TodoList app is an Azure Java application. It provides end-to-end CRUD operation to todo list item from front-end AngularJS code. Behind the scene, todo list item data store is Azure CosmosDB DocumentDB. This application uses [Azure CosmosDB] (https://github.com/Azure/azure-cosmosdb-java), [Azure DocumentDB] (https://docs.microsoft.com/en-us/azure/cosmos-db/sql-api-introduction) Spring Boot Starter, and AngularJS to interact with Azure. This sample application provides several deployment options to deploy to Azure, pls see deployment section below. With Azure support in Spring Starters, maven plugins and Eclipse/IntelliJ plugins, Azure Java application development and deployment is effortless now.

TOC

Requirements

Create Azure Cosmos DB documentDB

You can follow our steps using Azure CLI 2.0 to deploy an Azure Cosmos DB documentDB, or follow this article to create it from Azure portal.

  1. login your Azure CLI, and set your subscription id

    az login
    az account set -s <your-subscription-id>
  2. create an Azure Resource Group, and note your group name

    az group create -n <your-azure-group-name> -l <your-resource-group-region>
  3. create Azure Cosmos DB with DocumentDB kind. Note the documentEndpoint field in the response.

    az cosmosdb create --kind GlobalDocumentDB -g <your-azure-group-name> -n <your-azure-documentDB-name>

    Note name of cosmos db must be in lowercase.

  4. get your Azure Cosmos DB key, get the primaryMasterKey of the DocumentDB you just created.

    az cosmosdb list-keys -g <your-azure-group-name> -n <your-azure-documentDB-name>

Configuration

  • Note your DocumentDB uri and key from last step, specify a database name but no need to create it. Then modify src/main/resources/application.properties file and save it.

    azure.documentdb.uri=put-your-documentdb-uri-here
    azure.documentdb.key=put-your-documentdb-key-here
    azure.documentdb.database=put-your-documentdb-databasename-here
  • If you don't want to modify configuration in the source code manually, you can put variables in this file and set their values in system environment variables: DOCUMENTDB_URI, DOCUMENTDB_KEY and DOCUMENTDB_DBNAME. Then maven will substitute them during the build phase.

Run it

  1. package the project using mvn package
  2. Run the project using java -jar target/todo-app-java-on-azure-1.0-SNAPSHOT.jar
  3. Open http://localhost:8080 you can see the web pages to show the todo list app

Clean up

Delete the Azure resources you created by running the following command:

az group delete -y --no-wait -n <your-resource-group-name>

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.

When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Useful link

todo-app-java-on-azure's People

Contributors

abhinayagarwal avatar allxiao avatar eskibear avatar gavinfish avatar kaylangan avatar lastcoolnameleft avatar lenala avatar lgdoor avatar matthew-dong avatar microsoftopensource avatar msftgits avatar selvasingh avatar sophiaso avatar weldon0405 avatar xiangyan99 avatar xscript avatar yungezz avatar yuwzho avatar zhijunzhao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

todo-app-java-on-azure's Issues

README contents for deploying

README should contain distinct sections that cover the following:

  • Run the TODO App locally
  • Deploy to Azure Web Apps on Containers (Linux) - using Maven
  • Deploy to Azure Web Apps on Containers (Linux) - using IntelliJ
  • Deploy to Azure Web Apps on Containers (Linux) - using Eclipse
  • Deploy to Azure Web Apps on Containers (Linux) - using Jenkins
  • Deploy to Kubernetes in Azure Container Service - using Maven
  • Deploy to Kubernetes in Azure Container Service - using Jenkins

mvn wapper error

$ git clone [email protected]:Microsoft/todo-app-java-on-azure.git
$ cd todo-app-java-on-azure/
$ ./mvnw clean
Error: Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain

Simpler folder structure for sample app

image

Suggest that we use one folder for all the classes. It is a simple app. Let's put everything in the same package name - com.microsoft.azure.sample.todoapp or something like that

Question in settings.xml

The solution works fine and able to push docker image into Azure Container Registry
Is there a way to inject below fields (id, username and password) from Jenkins --> Maven --> pom.xml/settings.xml ? In the perspective of operation/password security it will be useful to avoid below hardcoding.

put-your-docker-registry-url
put-your-docker-username
put-your-docker-key

put-your-email

Can't debug TODOApplication in java9 env

Steps To Reproduce

  1. Clone code from https://github.com/Microsoft/todo-app-java-on-azure.git
  2. Open the cloned project and verify .project and .classpath files and target folder are generated.
  3. Open file todo-app-java-on-azure\src\main\resources\application.properties and replaces it with a test configuration
  4. Set BP on TodoListController.java on addNewTodoItem(@requestbody TodoItem item) and main on TodoApplication.java
  5. Press F5 choose java and F5 again to start debug, verify the BP on main is hit.
  6. Press F5 to continue
    Current Result
    image

UI incorrectly states successful creation

I have followed the instructions provided in the repo and everything appeared to be working correctly. I ran the mvn package, updated the credentials, ran java -jar target/todo-app-java-on-azure-1.0-SNAPSHOT.jar and then went to localhost:8080 and created a new item (which the UI said it completed).

Using the Data Explorer, I couldn't find any of the data. I then changed the credentials so that I knew that they'd be wrong and found that the app continued to say it would create/update items.

In short, the UI appears to be providing incorrect information by saying that it created the item successfully.

P.S. I even deleted the CosmosDB instance and it still claimed to successfully create the TODO item.

Can't debug TODO Application: Error Starting ApplicationContext

Platform: Mac & Linux

Repro steps:

  1. Open the cloned project and verify .project and .classpath files and target folder are generated.
  2. Open file todo-app-java-on-azure\src\main\resources\application.properties and replaces it with a test configuration
  3. Set BP on TodoListController.java on addNewTodoItem(@requestbody TodoItem item) and main on TodoApplication.java
  4. Press F5 choose java and F5 again to start debug, verify the BP on main is hit
  5. Press F5 to continue

Result:

 :: Spring Boot ::        (v2.0.3.RELEASE)

[INFO] TodoApplication - Starting TodoApplication on vsunxi00101 with PID 8928 (C:\Users\testuser\Downloads\todo-app-java-on-azure-master\todo-app-java-on-azure-master\target\classes started by testuser in C:\Users\testuser\Downloads\todo-app-java-on-azure-master\todo-app-java-on-azure-master)

[INFO] TodoApplication - No active profile set, falling back to default profiles: default

[INFO] AnnotationConfigServletWebServerApplicationContext - Refreshing org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext@61c4eee0: startup date [Wed Oct 31 08:12:00 UTC 2018]; root of context hierarchy

[INFO] TomcatWebServer - Tomcat initialized with port(s): 8080 (http)

2018-10-31 08:12:04.826  INFO 8928 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]

2018-10-31 08:12:04.826  INFO 8928 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet Engine: Apache Tomcat/8.5.31

2018-10-31 08:12:04.841  INFO 8928 --- [ost-startStop-1] o.a.catalina.core.AprLifecycleListener   : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: [C:\Program Files\Java\jdk1.8.0_181\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Program Files\Microsoft SDKs\Azure\Azure Dev Spaces CLI (Preview)\;C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files\Java\jdk1.8.0_181\bin;C:\Program Files\Git\cmd;C:\Program Files\apache-maven-3.5.4\bin;C:\Users\testuser\AppData\Local\Microsoft\WindowsApps;;C:\Users\testuser\AppData\Local\Programs\Microsoft VS Code\bin;.]

2018-10-31 08:12:05.132  INFO 8928 --- [ost-startStop-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext

[INFO] ContextLoader - Root WebApplicationContext: initialization completed in 4180 ms

[INFO] ServletRegistrationBean - Servlet dispatcherServlet mapped to [/]

[INFO] FilterRegistrationBean - Mapping filter: 'characterEncodingFilter' to: [/*]

[INFO] FilterRegistrationBean - Mapping filter: 'hiddenHttpMethodFilter' to: [/*]

[INFO] FilterRegistrationBean - Mapping filter: 'httpPutFormContentFilter' to: [/*]

[INFO] FilterRegistrationBean - Mapping filter: 'requestContextFilter' to: [/*]

[WARN] AnnotationConfigServletWebServerApplicationContext - Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'todoListController': Unsatisfied dependency expressed through field 'todoItemRepository'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'todoItemRepository': Unsatisfied dependency expressed through method 'setDocumentDbOperations' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.microsoft.azure.spring.data.cosmosdb.core.DocumentDbOperations' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}

2018-10-31 08:12:05.606  INFO 8928 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

[INFO] ConditionEvaluationReportLoggingListener - 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

[ERROR] LoggingFailureAnalysisReporter - 

***************************

APPLICATION FAILED TO START

***************************

Description:

Parameter 0 of method setDocumentDbOperations in com.microsoft.azure.spring.data.cosmosdb.repository.support.DocumentDbRepositoryFactoryBean required a bean of type 'com.microsoft.azure.spring.data.cosmosdb.core.DocumentDbOperations' that could not be found.

Action:

Consider defining a bean of type 'com.microsoft.azure.spring.data.cosmosdb.core.DocumentDbOperations' in your configuration.

The sample in the AI branch needs to be updated to show tracking dependencies

The AI branch shows how to configure a Java Springboot application with Application Insights. Currently the sample is only configured to show requests\responses within the app - but, does not track HTTP requests\responses with dependencies.

The steps that need to be completed are described here: https://docs.microsoft.com/en-us/azure/application-insights/app-insights-java-agent. In particular, make sure that the agent jar and the AI-Agent.xml files are located next to one another. Also, when launching the app's jar, make sure that you include "-javaagent=".

This work cannot be completed right now because there is a bug that causes an exception to be thrown when attempting to start the app. When this issue is fixed, this sample needs to be updated accordingly to track dependencies: microsoft/ApplicationInsights-Java#506

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.