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

前端 未结 9 1668
迷失自我
迷失自我 2020-12-07 09:29

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 d

相关标签:
9条回答
  • 2020-12-07 09:52

    I have an example which I have been using for couple years. Please take a look as a reference.

    https://github.com/bigzidane/springboot-rest-h2-swagger

    0 讨论(0)
  • 2020-12-07 09:57

    There is a somehow recommended directory structure mentioned at https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-structuring-your-code.html

    You can create a api folder and put your controllers there.

    If you have some configuration beans, put them in a separate package too.

    0 讨论(0)
  • 2020-12-07 10:00

    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.

    0 讨论(0)
  • 2020-12-07 10:01

    From the docs:, this is the recommended way

    0 讨论(0)
  • 2020-12-07 10:04

    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.

    0 讨论(0)
  • 2020-12-07 10:04

    https://medium.com/the-resonant-web/spring-boot-2-0-project-structure-and-best-practices-part-2-7137bdcba7d3

    I think this is a good structure. And it is a nicely written blog explaining the mindset of these choices.

    0 讨论(0)
提交回复
热议问题