'What is the recommended project structure for spring boot rest projects? [closed]

I'm a beginner with spring boot. I'm involved in the beginning of a project where we would build rest services using spring boot. Could you please advise the recommended directory structure to follow when building a project that will just expose rest services?



Solution 1:[1]

From the docs:, this is the recommended way

The following listing shows a typical layout:

com 
    +- example 
        +- myapplication 
            +- Application.java 
            +- customer 
                +- Customer.java 
                +- CustomerController.java 
                +- CustomerService.java 
                +- CustomerRepository.java 
            +- order 
                +- order.java 
                +- OrderController.java 
                +- OrderService.java 
                +- OrderRepository. java 
                

The Application. java file would declare the main method, along with the basic SpringBootApplication as follows:

package com.example.myapplication; 
import org. springframework.boot.springApplication; 
import org.springframework.boot.autoconfigure.SprinpootApplication; 

@SpringRootApplication public class Application { 
    public static void main(string[] args) 
        { 
            springApplication.run(Application. class, args); 
        }
}

Solution 2:[2]

config - class which will read from property files

cache - caching mechanism class files

constants - constant defined class

controller - controller class

exception - exception class

model - pojos classes will be present

security - security classes

service - Impl classes

util - utility classes

validation - validators classes

bootloader - main class

Solution 3:[3]

Though this question has an accepted answer, still I would like to share my project structure for RESTful services.

src/main/java
    +- com
        +- example
            +- Application.java
            +- ApplicationConstants.java
                +- configuration
                |   +- ApplicationConfiguration.java
                +- controller
                |   +- ApplicationController.java
                +- dao
                |   +- impl
                |   |   +- ApplicationDaoImpl.java
                |   +- ApplicationDao.java
                +- dto
                |   +- ApplicationDto.java
                +- service
                |   +- impl
                |   |   +- ApplicationServiceImpl.java
                |   +- ApplicationService.java
                +- util
                |   +- ApplicationUtils.java
                +- validation
                |   +- impl
                |   |   +- ApplicationValidationImpl.java
                |   +- ApplicationValidation.java

DAO = Data Access Object.
DTO = Data Transfer Object.

Solution 4:[4]

Use Link-1 to generate a project. this a basic project for learning. you can understand the folder structure. Use Link-2 for creating a basic Spring boot project. 1: http://start.spring.io/ 2: https://projects.spring.io/spring-boot/

Create a gradle/maven project Automatically src/main/java and src/main/test will be created. create controller/service/Repository package and start writing the code.

-src/main/java(source folder) ---com.package.service(package) ---ServiceClass(Class) ---com.package.controller(package) ---ControllerClass(Class)

Solution 5:[5]

Please use Spring Tool Suite (Eclipse-based development environment that is customized for developing Spring applications).
Create a Spring Starter Project, it will create the directory structure for you with the spring boot maven dependencies.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Subhasish Sahu
Solution 3 Paolo
Solution 4
Solution 5 Jobin