Quick-Start a Springboot Project

Want to write a back end web-service in Java and don’t know where to start? You’re at the right place. By the end of this article, you would have a springboot project running on a tomcat server, and you would also be able to create projects later without any difficulty.

I have worked with spring before, and the biggest advantage of springboot, at least when starting a new project, is that we don’t have to add entries and mappings for all our pages. In spring, the web.xml needs to contain all the mappings, which is not the case with springboot, which doesn’t have a web.xml file at all (it handles things for us). So let’s get started with creating a project.

Head over to start.spring.io and enter your project details, mainly the group id and artifact id. Under dependencies, make sure you add spring-starter-web, and you could add DevTools for faster reloading. You can also select a database dependency such as MySQL or PostgreSQL in case you plan on using it.

Once done, click on the Generate Project button, and it will start downloading the project as a zip file. Once the zip file is downloading, unzip the project and open it in the IDE of your choice. In case you’re using intelliJ (which I use), just open the pom.xml file, and it would give you an option to open it as a project. Add a tomcat plugin to the pom.xml file to add tomcat to your project (you could choose an alternative as well, such as jetty).

Once the project is open in the IDE of your choice, add a package under {your-group-id}.{your-artifact-id}, for example, in my case it could be something like com.shreyas.testproject. Let the package name be controller. Add a java class in this package (say, TestController). Add a Controller annotation to the java class, and add methods to this class, adding mapping annotations as required.

Use mvn clean install to build the project, and run the jar inside the target directory to run the project, with the command java -jar {jar-name}.jar . You can try the project in your browser at port 8080 if you have made no changes to the port.

You have a springboot web-service ready and running!

I hope this article helped, and if it did, don’t forget to give it a clap 👏. Follow me for more such stories, and feel free to drop a comment in case you encounter any issues, or for suggestions!

Written by

I’m a undergrad at BITS Pilani, Goa Campus, expecting to graduate in 2022. I love coding and writing about technical stuff.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store