When developing Spring Boot applications running on Domino, there is a feature which runs out of the box and makes developers happy: ScheduledTasks.
These are the equivalent for agents, but they are running directly in the HTTP task (which allows to access the complete Spring Application at runtime) and can be scheduled exactly to the milisecond.
To enable a scheduled task, you first have to add the @EnableScheduling annotation in your Application class:
package domino_spring.plugin;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
@SpringBootApplication
@EnableScheduling
public class Application extends org.springframework.boot.web.support.SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Next step is to declare the TaskScheduler used. Just add a bean to your Application class:
@Bean
public TaskScheduler taskScheduler() {
return new ConcurrentTaskScheduler();
}
After completing the setup you can define your scheduled task:
package domino_spring.plugin;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
@Component
public class ScheduledTasks {
private static final Logger log = LoggerFactory.getLogger(ScheduledTasks.class);
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
@Scheduled(fixedRate = 5000)
public void reportCurrentTime() {
log.info("The time is now {}", dateFormat.format(new Date()));
}
}
When the Sprint Boot application is now started, the current time is printed to the logs every 5 seconds.
What do you have to do to run Spring Boot apps on Domino?
1. Create an OSGi plugin
2. Add the required resources / libs / your app
3. Build & Deploy the plugin on the Domino server
4. Enjoy the result
I will upload a starter project asap.
P.S.
There was a Hands-On Session with Carsten @ EntwicklerCamp this year.
That (the starter project) would be really appreciated 😎
Just have a look here