You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jun 30, 2023. It is now read-only.
i have a spring boot application with thousands of rest controllers. i want to prevent these rest controllers to load when spring boot starts.
i want to be able to load them explicitly by importing the rest controller and initializing it in the main function.
please write code and configuration to make this possible
you can use the following approach to selectively enable your REST controllers:
Create a custom annotation for your REST controllers:
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface CustomRestController {
}
Annotate your REST controllers with the @CustomRestController annotation:
@CustomRestControllerpublicclassApiController {
// Your REST controller code
}
Create a custom BeanFactoryPostProcessor to register your REST controllers as beans:
In your main function, initialize the desired REST controllers and register them using the CustomRestControllerRegistrar:
@SpringBootApplicationpublicclassMySpringBootApplication {
publicstaticvoidmain(String[] args) {
SpringApplicationapp = newSpringApplication(MySpringBootApplication.class);
// Initialize the desired REST controllersList<Class<?>> controllers = newArrayList<>();
controllers.add(ApiController.class);
// Add more controllers as needed// Register the REST controllers as beansapp.addInitializers(applicationContext -> {
applicationContext.addBeanFactoryPostProcessor(newCustomRestControllerRegistrar(controllers));
});
app.run(args);
}
}
Now, only the REST controllers that you explicitly initialize and add to the controllers list in the main function will be loaded when the Spring Boot application starts.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
i have a spring boot application with thousands of rest controllers. i want to prevent these rest controllers to load when spring boot starts.
i want to be able to load them explicitly by importing the rest controller and initializing it in the main function.
please write code and configuration to make this possible
you can use the following approach to selectively enable your REST controllers:
@CustomRestController
annotation:BeanFactoryPostProcessor
to register your REST controllers as beans:CustomRestControllerRegistrar
:Now, only the REST controllers that you explicitly initialize and add to the
controllers
list in the main function will be loaded when the Spring Boot application starts.The text was updated successfully, but these errors were encountered: