Spring: Is there a simple non-website tutorial?

I am trying to create a Spring application (NOT a web application) to perform some simple tasks. In the end, they will connect to some other Spring applications over the network, but for now, I keep them simple. I have a CheckForNewItems class (timer extension) that is configured to run every 10 seconds.

I can confirm that it works by calling it programmatic:

public class Tester { public static ApplicationContext context; private void loadContext() { String filename = "beans.xml"; context = new FileSystemXmlApplicationContext(filename); } public static void main(String[] args) { Tester test = new Tester(); test.loadContext(); CheckNewItemsTask task = (CheckNewItemsTask)context.getBean("checkNewItemsTask"); } } 

Doing this works as expected, task.run () is called every 10 seconds. Now I need to figure out how to deploy this to a JBoss or Tomcat server so that it starts the task automatically.

Most of the tutorials I found only described how to get Spring MVC and servlets, not a standalone application. Does anyone know better?

Greetings Rob.

+4
source share
2 answers

You need a servlet that is configured to autostart when deployed. The servlet can then call your Tester class to initiate your "standalone" initialization process.

If you do not have a servlet (or perhaps another process associated with the server), specify your code, then the initialization process will never start.

+1
source

You do not need JBoss or Tomcat for this. If the application is headless and you are not going to add a user interface, consider jsvc for unix or procrun in windows. If you need the ability to control and control the application, and for this you do not need an appropriate user interface, you can watch JMX. This will work on the daemon without the rest of the Java EE stack.

If you have a maven project and you need an easy way to turn it into a daemon deployment application, you can use the maven appassembler to automate the process of creating a deployable daemon, setting up the directory structure of the application, scripts to start and stop, libraries and configuration files.

+6
source

All Articles