How to make repository be loaded lazily when I sta

2019-06-11 13:59发布

During development, after number of class increased, it take over 2 minutes until application is started.I think it makes our develop efficiency low...

And I found that if we add 'lazyInit=true', If I add this option, most of classes will be loaded lazily, but repositories are loaded even if I add this option.

@ComponentScan(basePackageClasses = LazyApplication.class,lazyInit=true)
@EnableAutoConfiguration(
)
public class LazyApplication {

    public static void main(String[] args) {
        SpringApplication.run(LazyApplication.class, args);
    }
}

Actually, our system have more than 300 repository and entity, so I want to make repository lazy too if possible.

How can I make my repository will Not be loaded when I start application but loaded when I access to the repository for the first time?

1条回答
时光不老,我们不散
2楼-- · 2019-06-11 14:46

You can use @Order annotation on your configuration classes to define load ordering.The highest precedence advice runs first. The lower the number, the higher the precedence. e.g

@Component
@Order(2)
public class MyRepo {
    public String getName() {
        return "some value";
    }
}
查看更多
登录 后发表回答