Search code examples
springspring-bootspring-data-jpaentitymanagerspring-profiles

How to minimize and speed up Spring Boot project for development enviroment?


I'm working on a Spring Boot Rest project with 500~ entity in it. But it is slow on start up duration (about 3 minutes) because of the EntityManagerFactory initialization. And it has 5GB~ memory allocation.

Using profiles I want to open a lightweighted version of my project. I'm trying to avoid some of the entities to be mapped via EntityManagerFactory. And related beans via ComponentScan.

Do you have any solution related this issue?

For example I wanna hide some of the packages from hibernate & spring boot auto configuration.

project files


Solution

  • If the class path scanning takes to long you can narrow it down to specific packages

    @ComponentScan(basePackages = "com.your.project")
    @EntityScan(basePackages = "com.your.project.model")
    @EnableJpaRepositories(basePackages = "com.your.project.repository")
    

    You also have an option to create a custom EntityManagerFactory as explained in this answer with a custom ConnectionProvider.