Spring Boot 1.2.3.RELEASE ApplicationReadyEvent not found - spring-boot

I am reading Spring Boot reference (version 1.2.3-RELEASE) and in point
22.4 Application events and listeners point 4 states:
"An ApplicationReadyEvent is sent after the refresh and any related callbacks
have been processed to indicate the application is ready to service requests."
So I tried:
SpringApplication app = new SpringApplication(LearnSpringBootApplication.class);
app.addListeners(new ApplicationListener<ApplicationReadyEvent>() {
...
but it cannot find the ApplicationReadyEvent. Has it been removed ?
If so - is there any equivalent for it ?
I found this post here:
Spring Boot - Wait for web server to start
but was wondering if there is another way?

Related

Spring boot GCP PUBSUB Consumer application

Can anyone share spring boot GCP PUBSUB subscriber application example, which keep running util externally killed (not rest api)?
Normally, our documentation instructs users to provide their own ThreadPoolTaskScheduler bean named pubsubSubscriberThreadPool with non-daemon threads to keep the application running. However, this seems to have stopped working and is currently an open issue.
In the meantime, you can provide a scheduled no-op process as a workaround:
#Scheduled (fixedRate = 1, timeUnit = TimeUnit.MINUTES)
public void ensureApplicationRuns() {
// do nothing, or log message
}

How to read events for newly modified record from keycloak to spring boot

Actually We have following flow and scenario to poll data in to my Spring boot App
Active Directory --> Keycloak --> Spring boot App
Here we are able to poll data in but in future if there is any record change in Active Directory keycloak has a provision to poll data in it's DB periodically but the same changed (Newly Added /Deleted /Updated ) records from key cloak to Spring boot application there is some eventing option but I do not see how and where to implement it ?
I suppose there should be a listener in the spring boot application which would get triggered on any change in record (Newly Added /Deleted /Updated ) of keycloak
The event listener is implemented on the Keycloak side. Here is an example of how to implement an event listener that logs events to console - Event Listener Example
Instead of logging, you will need to send notifications to your SpringBoot application in any suitable way:
you can implement some endpoint in your SpringBoot application that will be invoked by Even Listener's code
or Event listener can send let's say JMS message and your SpringBoot application will be subscribed to the JMS topic
etc.

Spring integration: Shutdown application when the handling of files is completed

How to create automatic shutdown in spring integration after finish all process for all files?
My application download undefined number of files and process all files sequentially, the flow is like this:
file:inbound-channel-adapter --> Transformer --> Splitter -->
http-outbound-gateway --> int:aggregator --> mail:outbound-channel-adapter.
At the End, i should shutdown my app.
How to know that all files are processed?
Anyone has an experience about it ?
Thanks
In you case you need to track your inbound directory.
You have to add another step to your flow (probably to track the last file).
I would suggest an ETL technique: Read file descriptions then process them.
When it will be processed you can send event to shutdown the app.
Spring boot application can be stopped by using ConfigurableApplicationContext:
SpringApplication app = new SpringApplication(Application.class);
ConfigurableApplicationContext context = app.run(args);
context.close();
Also there is another way using Spring Actuator shutdown endpoint:
See How to shutdown a Spring Boot Application in a correct way?
Spring Boot documentation

Gracefull shutdown on Jboss server 7

I have a scenario where i need to perform a gracefull shutdown on Jboss server 7 where my application needs to flush out all Objects from My application with proper logging and deleting out all the active session containing in my application . I am using spring 3.0 is there any thing provided by spring framework for this
You could implement an ApplicationListener or use a servlet context lifecycle listener instead:
Application context event handling
Servlet context event handling

Spring server start-up event

i am facing a problem. I am using tomcat server for my spring maven project and i want to subscribe my application to facebook once when server starts up. I have tried ApplicationListener ContextRefreshedEvent. It gets invoked on application context initialization, but the issue is at that time my server has not completely started and hence my application is not publically accessible which is required in my case as facebook subscription requires verification using application public URL. So i want to do subscription when my server gets started completey and not on application context initialization. Any idea how can i do it? Do i have nay application level event listener that can tell me that server has started completely?
Regards jia
You can annotate a bean method like so :
#PostConstruct
public void yrSubscribeLogic() {}
the app context can only be loaded after the server has fully started.

Resources