Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible/advisable to run Spring Boot without controllers just for the @ScheduledTasks and ORM?

I'd like to run a Spring Boot service without any of the controller-related stuff. I'd like it to just run a scheduled task every hour and do work if needed. I'm wanting to use Spring Boot, because I already know how to set the Hibernate ORM up, and I'm re-using a lot of the same repositories as another Spring Boot service. So, I spun up a new Spring Boot project and left out the start-web package.

The main issue I'm running into is that despite having a scheduled task set up, the service starts and immediately quits without running the scheduled task. In my head, I imagined the service kind of just sitting there, running, waiting for the time to trigger the scheduled job I have configured and kind of just sleeping until then. Are my expectations bad, or do I just have it misconfigured?

like image 808
Paul Springer Avatar asked Oct 11 '21 19:10

Paul Springer


People also ask

What do spring boot controllers do?

In Spring Boot, the controller class is responsible for processing incoming REST API requests, preparing a model, and returning the view to be rendered as a response.

When we should not use spring boot?

When you have a large number of different web apps, it can make sense to let the knowledge on that part only in the production team. In that case, you would not use Spring boot. On the other end, if the hosting is externalized, Spring boot allows to give a full package.

How do I run a Spring Boot application from the command line?

Running a Spring Boot application from the command line is pretty easy. Let’s see how to do it. If you are running a Maven project, you can build and run a Spring Boot application from the command line by adding the following maven plugin:

Can I use Spring Boot without a web server?

However, Spring Boot has a number of uses that do not require a web server: console applications, job scheduling, batch or stream processing, serverless applications, and more. In this tutorial, we'll look at several different ways to use Spring Boot without a web server. 2.

How to run Spring Boot without building a JAR file?

The alternate to run the spring boot without building the JAR file is to run the command mvnspring-boot:run. This command makes sure that the POM.xml has the plugin which signifies that we want to use Tomcat to run our code.

How to create multiple commandlinerunners in Spring Boot?

Spring Boot adds CommandLineRunner interface into the startup process. Hence throwing exception in commandlinerRunner will force Spring boot to abort startup. We can create multiple CommandLineRunners in one application. Using the Ordered interface or @Order annotation we can configure the order in which they should run.


1 Answers

I've solved the problem. It was a configuration issue causing the Spring Boot app to not recognize the presence of required configuration values in the application.properties file.

like image 194
Paul Springer Avatar answered Oct 27 '22 04:10

Paul Springer