Skip to content

Instantly share code, notes, and snippets.

@o
Created May 30, 2016 16:37
Show Gist options
  • Save o/86f205c5172f40c12c63d9121b26d861 to your computer and use it in GitHub Desktop.
Save o/86f205c5172f40c12c63d9121b26d861 to your computer and use it in GitHub Desktop.

I'd done a lot of Boot projects before. But never tried multi-module structure.

Here is the my sample structure

Parent project: com.github.o.parent

Just declares org.springframework.boot-spring-boot-autoconfigure

Common project: com.github.o.common

Holds entities, repositories and repository related service classes. Only have a configuration class for HikariCP data source. Question: Which annotations (especially JPA related) right for this configuration class?

Rest project: com.github.o.rest

Depends to JPA project. Needs to use common project service classes. Also have a Application class with SpringBootApplication. Question: Same, which annotations needed for scanning common project services and repositories.

I'd tried different annotations / configurations but i can't inject a repository from common project.

Thanks.

@joshlong
Copy link

joshlong commented May 30, 2016

Well, ok, there are two things worth addressing here:

you gain nothing by keeping entities and services in a separate maven module.

Imagine you have the following services, orders, customers, etc.

orders

  • src/{test,main}/{java,resources}/{OrderApplication.java,Order.java,OrderRestController.java,OrderRepository.java (and maybe OrderService.java)}

customers

    • src/{test,main}/{java,resources}/{CustomerApplication.java,Customer.java,CustomerRestController.java,CustomeRepository.java (and maybe CustomerService.java)}

Here, you're dividing things logically. Create a new Spring Boot application for each one, starting from start.spring.io. (Choose Web, and JPA (or MongoDB or JOOQ or any of the far more powerful alternatives besides JPA).

communication between services happens in terms of REST or messaging.

@joshlong
Copy link

the second ting you're asking about is how to layer configuration for annotations. this should be less of an issue if you use the above approach.

@eruiz
Copy link

eruiz commented May 30, 2016

Imho a project organized in Maven modules will give you more or less benefits depending on the application type: monolithic or microservices.

Maybe microservices based applications can be organized in the way said by Josh ... but organizing monolithic applications in Maven modules makes the maintenance, API distribution, etc. more comfortable.

Spring Roo 2.0.0.M2 generates multimodule Spring Boot applications. Download it from http://projects.spring.io/spring-roo/, install it and run

project setup --topLevelPackage org.sprfw.petclinic --multimodule STANDARD --projectName PetClinic

You will get a nice Spring Boot multimodule project.

@wbiller
Copy link

wbiller commented May 30, 2016

Actually this also works well for monolithic applications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment