Friday, April 8, 2011

Sample Spring Configuration File in Spring 3.0

When building large enterprise applications, developer usually ends up with a lot of spring beans configured into Spring ApplicationContext. ApplicationContext allows us to interact with the configured beans.

Following is an example of basic 3.0 spring configuration file:

Spring provides extensive support for namespaces. In the above example, bean namespace is used for defining all basic definitions of the application and context namespace is provided for convenience for configuring core beans.

The property-placeholder will automatically locate and parse any property files you have in your classpath under the META-INF/spring directory.

The context:component-scan declaration will cause Spring to locate every @Component, @Repository, and @Service in your application. This allows you to write a POJO, and then simply annotate the new POJO as a @Service. Spring will then automatically detect, instantiate, and dependency inject your service at startup time.
The exclude-filter is declared to avoid instantiating our @Controller classes, as these should be instantiated by a web tier application context. 
Imports allow you to specify an external Spring configuration file to be integrated into your application context.

No comments: