Home > database >  How to structure a spring boot project that doesn't interact with a database
How to structure a spring boot project that doesn't interact with a database

Time:10-14

I have worked with Spring Boot Data JPA and generally, the project structure would look like this

my-app/
├─ com.company/
│  ├─ model/
│  ├─ controller/
│  ├─ service/
│  ├─ repository/
│  ├─ MyAppMainClass.java

where each folder represents its function in a general sense.

model/ has entity classes
controller/ has controller classes that have the routes configured for the app
service/ has service classes that have the logic to process a request
repository/ has repository classes that interact with the database and get the response back

Now I have a very simple project where I don't have a database component, but all I need to do is call a few other REST APIs and return the response.

So should I follow the same structure and just remove the repository folder and put all the calls to the other REST APIs in the classes in the service folder?

Or is there any other structure that is generally better suited for this? Maybe if there are some inconsistencies in my understanding about all this please correct me. Thanks :)

CodePudding user response:

I would replace the repository package with a consumer package. And create for each resource a consumer.

my-app/
├─ com.company/
│  ├─ model/
│  ├─ controller/
│  ├─ service/
│  ├─ consumer/
│  ├─ MyAppMainClass.java

CodePudding user response:

Just remove the repository package,

my-app/
├─ com.company/
│  ├─ model/
│  ├─ controller/
│  ├─ service/
│  ├─ MyAppMainClass.java
  • Related