You could take a look at @RefreshScope.
I would define my @RestController beans as follows:
@Configuration
@RefreshScope
public ControllerConfig {
@Bean
@ConditionalOnProperty(value = "should.initialize.rest", havingValue = true)
public SomeController someController(){
....
}
@Bean
@ConditionalOnProperty(value = "should.initialize.rest", havingValue = true)
public SomeOtherController someOtherController(){
....
}
}
and if you start your application with property should.initialize.rest with value false in your application.properties:
should.initialize.rest=false
Then your controllers won't be registered/initialized. When the application is running, you could then update your application.properties to:
should.initialize.rest=true
and make a call to /refresh, then your ApplicationContext will reload/refresh, this time with your REST controllers. You can find more about @RefreshScope below:
ApplicationContext. Did you have a look at@RefreshScope? - Hasan Can Saral