By Markus Sprunck; Revision: 1.2; Status: final; Last Content Change: Apr 28, 2013; This article describes a minimal standalone spring application on Spring 2.5.6 Framework. To start with Spring-Framework it is not necessary to use all parts of the framework and/or to work with a web application. The Spring-Framework can also used for small standalone applications. You need just some minutes setup your own application. In this tutorial Spring 2.5 with a pure XML configuration is described. The use of annotations is described in the article A Minimal Java Application Sample Based on Spring 3.1 Framework. Sample CodeThe following example demonstrates how easy it is to use Spring-Framework in a standalone application - just 4 files are needed:// File #1: MinimalSpringApp.java
// File #2: application-config.xml
If you run this small program, you should see something like this:
20.03.2012 20:57:41 org.springframework.context.support.AbstractApplicationContext prepareRefreshINFO: Refreshing org.springframework.context.support.FileSystemXmlApplicationContext@d1e604: org.springframework.context.support.FileSystemXmlApplicationContext@d1e604]; startup date [Tue Mar 20 20:57:41 CET 2012]; root of context hierarchy20.03.2012 20:57:41 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitionsINFO: Loading XML bean definitions from URL [file:/C:/Projects/.eclipse3.7.rcp/MinimalSpringApp/bin/com/sprunck/sample/application-config.xml]20.03.2012 20:57:41 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory INFO: Bean factory for application context [org.springframework.context.support.FileSystemXmlApplicationContext@d1e604]: org.springframework.beans.factory.support.DefaultListableBeanFactory@18aaa1e20.03.2012 20:57:41 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@18aaa1e: defining beans [fooId]; root of factory hierarchyHello World - from FooNeeded LibrariesTo bring all the files together, the following 4 libraries:
are needed in the build path. Project Structure |
