Blog_Banner_Asset
    Homebreadcumb forward arrow iconBlogbreadcumb forward arrow iconFull Stack Developmentbreadcumb forward arrow iconHow To Create Spring Boot Project In Eclipse

How To Create Spring Boot Project In Eclipse

Last updated:
27th May, 2021
Views
Read Time
8 Mins
share image icon
In this article
Chevron in toc
View All
How To Create Spring Boot Project In Eclipse

Java programming language is often said to be too complicated and cumbersome in terms of building simple applications. However, Java provides a stable platform that offers an extremely mature ecosystem which makes it possible for developers to create robust software without much hassle. 

The Spring Framework – one of the many powerful frameworks present in the Java ecosystem – brings with it a collection of configuration and programming models to simplify the development and testing of applications in Java. 

In this article, we’ll go through some of the useful features of the STS IDE (Eclipse Spring Tool Suite), which are useful for you when developing Spring Boot projects or applications in Eclipse. We’ll talk about the various benefits of STS as opposed to the traditional way of building Spring applications with Eclipse. 

Check out our free courses to get an edge over the competition

Ads of upGrad blog

Then, we’ll look at how to bootstrap an application, how to execute it, and eventually, how to add additional dependencies. Finally, we’ll conclude this tutorial by adding applications arguments. 

Main Features of STS 

Spring Tool Suite, short for STS, is a development environment based on Eclipse that is specifically customized for creating seamless Spring Boot projects and applications. 

STS provides a ready-to-use environment for developers for implementing, debugging, running, and deploying their Spring applications. STS also includes integration for Pivotal tc Server, Pivotal Cloud Foundry, Git, Maven, and AspectJ. 

Spring Tool Suite is a suite that’s built as an additional layer on top of the latest Eclipse releases. 

Check out upGrad’s Advanced Certification in Cloud Computing

Project Configuration

STS understands all the basic Java project structures. The tool parses configuration files and displays detailed information about the defined beans, injected dependencies, used namespaces, and extracts overviews for certain stereotypes. 

STS Features Overview

Eclipse STS provides quick fixes for your Spring applications while validating your project. For instance, when you are working with Spring Data JPA, the Eclipse IDE may be used to validate query method names.

Check out upGrad’s Advanced Certification in Blockchain

Spring Tool Suite also provides an easy to understand the graphical view of the various bean methods and the relationships they hold. If you want to take a closer look at the different graphical editors that come with STS, you can check the views that are available under the menus window, show view, and then Spring respectively.

The STS also offers developers additional features that are not limited to the applications of Spring. You can check the full list of features here.

Explore Our Software Development Free Courses

Creating a Spring Application

Let’s start by bootstrapping a simple application. Without STS, the Spring application can be created using the Spring Initializer website or the Spring Boot CLI. This can be further simplified by clicking on Create Spring Starter Project from the STS dashboard.

In the ‘New Spring Starter Project’ screen, either use the default settings or make the required adjustments as per your project, and then go to the next screen. There, select ‘Web’ and click finish.

Your pom.xml should now look something like this:

<parent>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-parent</artifactId>

    <version>2.4.0</version>

    <relativePath/> <!– lookup parent from repository –>

</parent>

<properties>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

    <java.version>1.8</java.version>

</properties>

<dependencies>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-web</artifactId>

    </dependency>

    <dependency>

        <groupId>org.springframework.boot</groupId>

        <artifactId>spring-boot-starter-test</artifactId>

        <scope>test</scope>

    </dependency>

</dependencies>

If you’re running an older version fo Spring Boot, please find the latest version here.

Explore our Popular Software Engineering Courses

Running the Application

The previously mentioned application can be started by simply right-clicking on the project and selecting ‘run as Spring Boot App’. Without STS, you can run the application from CLI using the following commands: 

$ mvn spring-boot:run

By default, the Spring applications are started with Tomcat that runs on port 8080. At this point, the applications start on port 8080 but don’t perform any task as we haven’t implemented any code in it yet. 

upGrad’s Exclusive Software Development Webinar for you –

SAAS Business – What is So Different?

 

Logging and ANSI Console

When you execute the project from your IDE using the ‘run’ command, you’ll find that the console outputs some colour-coded log statements. In case you want to turn these statements off, you can go to ‘run configurations’ and disable the checkbox that says ‘Enable ANSI console output on the Spring Boot tab’. 

Alternatively, you can also disable the logging statements by setting a properties value in the applications.properties file like this: 

spring.output.ansi.enabled=NEVER

JPA Query Name Checks

At times, implementing a data access layer may turn into a cumbersome activity. A lot of boilerplate code may need to be written to realize extremely simple queries and perform pagination.  Spring Data JPA aims to seamlessly facilitate such an implementation of data access layers. 

To get started, add the following dependency for JPA to the previously generated pom.xml:

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-data-jpa</artifactId>

</dependency>

<dependency>

    <groupId>com.h2database</groupId>

    <artifactId>h2</artifactId>

</dependency>

You might have noticed that your version has not been specified in the above declaration. This is because of the fact that dependencies are managed by the spring-boot-starter-parent. 

To make the JPA work, you’ll need to properly define entity and transaction managers for your project. However, working with Spring auto-configures these values for you. The only thing left to do from your end is to create the actual entity classes. 

These entities are managed by the entity manager which is created by the container. Let’s create an entity class called Foo: 

@Entity

public class Foo implements Serializable {

    @Id

    @GeneratedValue

    private Integer id;

    private String name;

 

    // Standard getters and setters

}

The container will scan all the classes annotated with @Entity from the root of the configuration package. 

Next, let’s create JPA repository for the Foo entity:

public interface FooRepository extends JpaRepository<Foo, Integer> {

    public Foo findByNames(String name);

}

At this stage, you might have already noticed that your IDE now flags this query method with the following exception: 

Invalid derived query! No property names found for type Foo!

This happens due to the fact that you have accidentally written an extra ‘s’ at the end of the method name of the JPA repository. To fix this exception, remove the extra s and make it like: 

public Foo findByName(String name);

In-Demand Software Development Skills

Jar Type Search

Jar Type Search is a feature that was introduced in the 3.5.0 version of STS. This feature provides content-assisted proposals for classes that aren’t yet in the classpath. STS helps developers in adding dependencies to their POM files, in case they aren’t on the classpath. 

For instance, let us add a line to the Foo entity class. For this to work properly, please ensure that the import statement for java.util.List is already present. 

Now we may add Google Guava as follows:

private List<String> strings = Lists // ctrl + SPACE to get code completion

The IDE then suggests several dependencies to be added to the classpath. Add these dependencies from com.google.common.collect, press return, and add the dependency from Guava. 

The Guava jar will automatically be added to your pom.xml file like following: 

<dependency>

    <groupId>com.google.guava</groupId>

    <artifactId>guava</artifactId>

    <version>19.0</version>

</dependency>

Adding Application Arguments

One of the most powerful features of the Spring framework is the support of external configurations that can be passed to applications in several ways – as a command-line argument, specified in properties of YAML files, or as system properties. Let’s look at how to add a configuration option as an application start argument using STS. 

This is illustrated by configuring Tomcat to start on a different port.

In order to run a Spring application on a Tomcat port other than the default (8080) one, you need to use the command below. In the following command, a custom port is specified as the command line argument. 

mvn spring-boot:run -Drun.arguments=”–server.port=7070″

Ads of upGrad blog

Learn Software development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs, or Masters Programs to fast-track your career.

Conclusion

In this article, we went through how to execute Spring projects and applications in STS. However, this is not all – there are many more useful features that can be utilized during the development process. While this tutorial was good to get you started with creating Spring Boot Project in Eclipse STS, remember that there’s a lot for you to explore and experiment from. 

If you’re interested to learn more about Java, full-stack software development, check out upGrad & IIIT-B’s Executive PG Program in Full-stack Software Development which is designed for working professionals and offers 500+ hours of rigorous training, 9+ projects, and assignments, IIIT-B Alumni status, practical hands-on capstone projects & job assistance with top firms.

Profile

Rohan Vats

Blog Author
Software Engineering Manager @ upGrad. Passionate about building large scale web apps with delightful experiences. In pursuit of transforming engineers into leaders.

Frequently Asked Questions (FAQs)

1What is spring boot?

2What is spring hibernate?

Spring hibernate is an open-source framework used to develop enterprise java applications. Spring framework handles the most important tasks in any java application. It allows developers to make changes in the code without any side effect. It allows the readability of the code and simplifies the error handling of the application. It supports the data access and data mapping. Hibernate framework is a java-persistence framework for the object-oriented programming language java. It provides the features for managing relational data in java. Hibernate supports the Java data abstraction layer (jdo), java remote method invocation (rmi), and the Java transactional interface.

3What is spring initializr?

Spring Initializr is a handy online tool for getting started with Spring. It generates projects based on what you need. Whether you are looking for a simple CRUD application, or a full-blown web application, this little site will get you started with coding in no time. Populate your project with your choice of technology (Java, Groovy, Grails, etc) and it will generate the basic project structure and dependencies. You can add further dependencies or customize the project to your needs. Spring Initializr is a really cool tool that makes it easy to start a new Spring Boot project. It generates the project structure and configuration files that you can then customize. It also gives you a selection of technologies on which the project can be based, so you get the advantage of choice without the disadvantage of having to do the work yourself.

Explore Free Courses

Suggested Blogs

How to Rename Column Name in SQL
46648
Introduction We are surrounded by Data. We used to store information on paper in enormous file organizers. But eventually, we have come to store it o
Read More

by Rohan Vats

04 Mar 2024

Android Developer Salary in India in 2024 [For Freshers &#038; Experienced]
900965
Wondering what is the range of Android Developer Salary in India? Software engineering is one of the most sought after courses in India. It is a reno
Read More

by Rohan Vats

04 Mar 2024

7 Top Django Projects on Github [For Beginners &amp; Experienced]
50999
One of the best ways to learn a skill is to use it, and what better way to do this than to work on projects? So in this article, we’re sharing t
Read More

by Rohan Vats

04 Mar 2024

Salesforce Developer Salary in India in 2024 [For Freshers &#038; Experienced]
908377
Wondering what is the range of salesforce salary in India? Businesses thrive because of customers. It does not matter whether the operations are B2B
Read More

by Rohan Vats

04 Mar 2024

15 Must-Know Spring MVC Interview Questions
34519
Spring has become one of the most used Java frameworks for the development of web-applications. All the new Java applications are by default using Spr
Read More

by Arjun Mathur

04 Mar 2024

Front End Developer Salary in India in 2023 [For Freshers &#038; Experienced]
902189
Wondering what is the range of front end developer salary in India? Do you know what front end developers do and the salary they earn? Do you know wh
Read More

by Rohan Vats

04 Mar 2024

Method Overloading in Java [With Examples]
25538
Java is a versatile language that follows the concepts of Object-Oriented Programming. Many features of object-oriented programming make the code modu
Read More

by Rohan Vats

27 Feb 2024

50 Most Asked Javascript Interview Questions &#038; Answers [2024]
3834
Javascript Interview Question and Answers In this article, we have compiled the most frequently asked JavaScript Interview Questions. These questions
Read More

by Kechit Goyal

26 Feb 2024

OOP Concepts and Examples That Every Programmer Should Know
25126
In this article, we will cover the basic concepts around Object-Oriented Programming and discuss the commonly used terms: Abstraction, Encapsulation,
Read More

by Rohan Vats

26 Feb 2024

Schedule 1:1 free counsellingTalk to Career Expert
icon
footer sticky close icon