Establishing connections to external systems (databases etc) as part of the spring context construction seems like bad idea. Does the framework contain any method for actual application lifecycle management ? Since I'm running in embedded-mode, my best suggestion yet is to use a ListableBeanFactory to get all the beans and make an interface with start/stop/isRunning on all the application beans. Do I have to roll my own or is there something within spring I can use ?
Spring has the Lifecycle
interface which you can implement. This interface provides basic start
, stop
and isRunning
methods.
You could also implement the SmartLifecycle
interface which allows for a little more control over when something is invoked due the the additional Phased
interface.
See also How does Lifecycle interface work in Spring? What are "top-level singleton beans"? and Load spring context in phases.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With