Spring Boot in Visual Studio Code
Visual Studio Code is an ideal lightweight development environment for Spring Boot application developers and there are several useful VS Code extensions including:
Create the project
The Spring Initializr extension allows you to search for dependencies and generate new Spring Boot projects.
To install, launch VS Code and from the Extensions view (⇧⌘X (Windows, Linux Ctrl+Shift+X)), search for
Once you have the extension installed, open the Command Palette (⇧⌘P (Windows, Linux Ctrl+Shift+P)) and type
Spring Initializr to start generating a Maven or Gradle project and then follow the wizard.
Develop the application
The Spring Boot Support extension includes rich language support for working with Spring Boot
The extension supports quick navigate through source code, smart code completions, quick access to running apps, and live application information. Similar code completion and validation features are also available for
Connect with data services
Azure Cosmos DB is a globally-distributed database service that allows developers to work with data using a variety of standard APIs, such as SQL, MongoDB, Cassandra, Graph, and Table.
The Spring Boot Starter makes it easy to store data in and retrieve data from your Azure Cosmos DB with SQL API.
Before running this sample on Azure, you need to have an Azure subscription.
If you don't have an Azure subscription, you can sign up for a free Azure account:
Create an Azure Cosmos DB entity on Azure
- Go to Azure portal and click the '+' to Create a resource .
- Click Databases, and then click Azure Cosmos DB to create your database.
- Select SQL (Document DB) API and type in other information for your database.
- Navigate to the database you have created, and click Keys and copy your URI and PRIMARY KEY for your database.
Config your project
You can start from the Spring Data Azure Cosmos DB Sample Project.
application.properties. Replace below properties in
application.propertieswith information of your database.
azure.documentdb.uri=your-documentdb-uri azure.documentdb.key=your-documentdb-key azure.documentdb.database=your-documentdb-databasename
Run and debug the application
You can press F5 to run your application. To check the result, open Azure portal and access your Cosmos DB. Click Data Explorer, and next choose Documents. You will see data being shown if it is successfully written into Cosmos DB. You can also browse your data entries in Cosmos DB with Azure Cosmos DB Extension.
After setting a breakpoint (F9) in your source code, refresh your browser to hit the breakpoint. Details about debugging can be found in Java Debugging
Alternatively, you can also use Maven to package and run your project as steps below:
Navigate to the directory
azure-spring-bootand run the command.
Navigate to the directory
azure-documentdb-spring-boot-sampleand run the command.
mvn package java -jar target/azure-documentdb-spring-boot-sample-0.0.1-SNAPSHOT.jar