Using Spring outside a WebApp
Hi,
Apologies if this is a daft question...
I have used Spring in the past and found it very useful for injecting my dependencies and otherwise configuring my application. However I have never built a Spring app from scratch - the basic project has always been in place.
I'd like to use Spring to configure my current application. It isn't currently a web app, however, there may be a presentation web layer added in the future. Any start up guide I have found so far assumes a current web layer.
So I suppose my first question is: is Spring a suitable tool for the job? And secondly, if it is, the can anyone point me towards a tutorial that describes how to set up a non-web Spring application?
Again, apologies if this is a silly question and/or I've missed a fundamental point somewhere along the line :rolleyes:
Cheers :)
My app is servere-based, not web-based
I have a server app that provides services without any web components. Its not too hard. You just have to code some startup class.
Code:
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class MyServerApp{
public static void main(String[] args) {
ApplicationContext appContext =
new ClassPathXmlApplicationContext(
new String[] {"myServerApplicationContext.xml"});
/* Touching the bean will cause it to get instantiated. */
appContext.getBean("serverBean1");
appContext.getBean("serverBean2");
try {
while (true) {
Thread.sleep(10000);
}
} catch (InterruptedException e) {
System.out.println("My server app is shutting down.");
}
}
}
This taps the beans, and Spring creates them. My beans expose themselves through CORBA, but you can expose them through any means you wish. Spring is great at supporting this. And if you wish to write something like a Swing front end, just give it something like the code above, and have a separate clientApplicationContext.xml with the necessary hooks to talk by remoting to the server app.