dimanche 29 mars 2020

What is the recommended code structure in Java for springboot based REST microservice?

What is the recommended code structure in Java for springboot based REST web service (microservice)? What I have seen in some java projects and also managed to deduce after searching on internet is below

ApplicationMainClass (hosting static void main())

<EntityA>
    <EntityA>.java
    <EntityA>Controller.java
    <EntityA>Service.java
    <EntityA>Repository.java

<EntityB>
    <EntityB>.java
    <EntityB>Controller.java
    <EntityB>Service.java
    <EntityB>Repository.java

pom.xml

etc

Q1. Is that how (i.e. above) the code in project should be structured or why not something like below as well

ApplicationMainClass (hosting static void main())

Entities
    <EntityA>.java
    <EntityB>.java
Controllers
    <EntityA>Controller.java
    <EntityB>Controller.java
Services
    <EntityA>Service.java
    <EntityB>Service.java
Respositories
    <EntityA>Repository.java
    <EntityB>Repository.java

pom.xml

Q2. Are there any other component/layer (i.e. apart from controller, Service, Respository) that should be in code structure?

Q3. Is their any best practices documentation or blog which I can refer so that I start with a meaningful code structure rather than starting with something which then have to be refactor-ed later.

Aucun commentaire:

Enregistrer un commentaire