Spring Into Action With GitHub Code Spaces

Spring Into Action With GitHub Code Spaces

Hello friends today we'll learn to use GitHub Code spaces.

Prerequisites:

  • A Blank GitHub Repo with README file.
  • Familiarity with Spring Boot.


so let's start with,

What is GitHub Code spaces ?

GitHub Coe spaces provides the pre-configured environment and look & feel like vs code all out of the box in the cloud, imagine like this, if you want to do very small changes & test the code what are the steps you'll have to perform.

  1. Install the IDE
  2. Set up the environment for the project
  3. Clone the project from the GitHub & import it into your IDE
  4. Try running it.

And if you miss some configuration, you'll encounter errors.


With GitHub Codespaces, you can avoid these steps and get straight to coding.

Starting with Code Spaces

I assume that you have the GitHub repository.

Article content
GitHub Repository


Click on code & switch to the code spaces tab & click on create code space on main

Article content
create codespace on main


In very few seconds you'll see something like this in your browser

Article content
codespace


now let's install all the necessary extensions that we are going to need for our spring boot project. Spring boot Extension Pack

Article content
installing spring boot extension pack

Extension pack for java

Article content
installing Extension pack for java


Use Spring Initializr to create a simple project

I have additionally added the sayHello() method & annotated the class with @RestController

Article content
simple Hello World Code


Let's hit the run & see the results, click on open in browser when your app is up and running

Article content
running the app


Here it is, your first Spring Boot application running in a Codespace!

Article content
Hello from code spaces



Let's Do Some Advance Part

Persisting the configuration

let say you are working in a team, and want to share this amazing feature with your team also, but they'll also need to set up the extensions, & all the things we've just did before start working on the actual implementation part, to simplify this we have devcontainers.

devcontainers manages our all the configurations, so that when anyone create a code space just like we did from the repo they will get all the extensions & every configuration that you do by default. let's configure this.


Click

ctrl + shift + p        


Search for codespace

You'll find the first option Add Dev Container Configuration Files.

Article content
Add Dev Container Configuration Files.

Select Create new configuration

Search & Select Java or Java & PostgreSQL.

Article content
creating configuration

You will see the json like this

You can customize it according to your needs.

For now we will just add some extensions.

Article content
looking at devcontainer.json


Click on extension select Add to devcontainer.json

also add other extensions like this

Article content
adding Extensions to devcontainer.json


After adding Extensions our devcontainer.json will look something like this.

Article content
final version of devcontainer.json


now commit the changes & whenever someone opens your repo in codes spaces, they will get all the configuration out of the box, they can just start implementing the task, without worrying about environment & configuration.


I hope this article was helpful for you. If you found it valuable, please share it with your friends and fellow developers. Your support will encourage me to write more articles like this one.

Thank you for reading!

Guilherme Bayer

Senior Frontend Engineer | 10+ YOE | React | Next.js | TypeScript | JavaScript | Node.js

10mo

That's the way to go. Leveraging Codespaces for Spring Boot development is a game-changer. Streamline your workflow and build those awesome apps effortlessly.

To view or add a comment, sign in

More articles by smit J.

  • Exploring Design Patterns - Singleton design pattern

    Singleton Design Pattern Singleton design pattern is the easiest design pattern to get into the world of design…

  • Design Patterns - Overview

    Design patterns are the way to solve the common problem's that occur during the development of application, or…

Insights from the community

Others also viewed

Explore topics