What is the recommended project structure for spring boot rest projects?

We Are Going To Discuss About What is the recommended project structure for spring boot rest projects? . So lets Start this Java Article.

Advertisements
  1. What is the recommended project structure for spring boot rest projects?

    Though this question has an accepted answer, still I would like to share my project structure for RESTful services.
    src/main/java +- com

  2. What is the recommended project structure for spring boot rest projects?

    Though this question has an accepted answer, still I would like to share my project structure for RESTful services.
    src/main/java +- com

Solution 1

Advertisements

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); 
        }
}

Original Author ENDEESA Of This Content

Solution 2

Advertisements

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

Original Author Subhasish Sahu Of This Content

Solution 3

Advertisements

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.

Original Author Amar Prakash Pandey Of This Content

Solution 4

Advertisements

You do not need to do anything special to start. Start with a normal java project, either maven or gradle or IDE project layout with starter dependency.

You need just one main class, as per guide here and rest…

There is no constrained package structure. Actual structure will be driven by your requirement/whim and the directory structure is laid by build-tool / IDE

You can follow same structure that you might be following for a Spring MVC application.

You can follow either way

  • A project is divided into layers:

    for example: DDD style

    • Service layer : service package contains service classes
    • DAO/REPO layer : dao package containing dao classes
    • Entity layers

    or

    any layer structure suitable to your problem for which you are writing problem.

  • A project divided into modules or functionalities or features and A module is divided into layers like above

I prefer the second, because it follows Business context. Think in terms of concepts.

What you do is dependent upon how you see the project. It is your code organization skills.

Original Author The Mighty Programmer Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment