Spring by Example

Skip to main content.

Spring Examples

Most Recent Examples

Topic Spring Version Description Creator
Spring Modules with Commons Configuration 2.5 Spring Modules Jakarta Commons example loading properties from a database. This example will show you how to use a DatabaseConfiguration from the Jakarta Commons Configurations project to load the Database Properties into your application context. DanielP
Simple Spring Web Services 2.5 A very simple example of using Spring Web Services 1.5.x with JAXB for marshalling and unmarshalling requests. A JAXB plugin for Maven is used to generate the JAXB beans from and XSD and the XSD is reused to generate a WSDL. The response from the server sends a person list, but could easily be modified to retrieve person based on an ID. DavidWinterfeldt
Simple GWT Spring Webapp 2.5 This enhances the Spring Web Flow Subflow Webapp by using GWT (Google Web Toolkit) version 1.5-RC1 for a GWT table widget on the search page. The example also uses Spring JS to submit the person form by using Spring.remoting.submitForm to only update the content div. Dynamic Tiles Spring MVC Module? (version 1.1) has been updated to support rendering Tiles fragments like AjaxTilesView and FlowAjaxTilesView in Spring JS and Spring Web Flow. DavidWinterfeldt
Spring by Example JDBC 2.5 The Spring by Example JDBC module has some utilities to help creating and initializing a database. There is an extension of SimpleDriverDataSource from Spring, which doesn't pool connections, that can be configured to run scripts once the class is initialized and another one based on Commons DBCP BasicDataSource. The script processor that they use can also be used separately. DavidWinterfeldt
One to Many JPA Hibernate Configuration 2.5 One to Many JPA configuration using Hibernate that can to find, save, and update a record. There is a Person that has a one-to-many relationship to Address. This example is very similar to One to Many Hibernate Annotation Configuration example since that example was already using javax.persistence annotations to configure the Person and Address beans. DavidWinterfeldt
Spring Web Flow Subflow Webapp 2.5 A Spring Web Flow 2.0 example using a flow to create and edit a Person and a subflow to create and edit a Person's Addresses. A Spring MVC annotation-based controller still handles search and deleting Person records. The example is built on Simple Spring Web Flow Webapp which can be referred to if necessary. DavidWinterfeldt
Simple Spring Web Flow Webapp 2.5 A very simple Spring Web Flow 2.0 example using a flow to create and edit a Person. A Spring MVC annotation-based controller still handles search and deleting records. The example is built on Simple Spring MVC Form Annotation Configuration Webapp and Simple Spring Security Webapp which can be referred to for better explanations of Spring MVC Annotations and Spring Security. DavidWinterfeldt
Simple Spring Security Webapp 2.5 Simple Spring Security 2.0 example securing a webapp based on the Simple Spring MVC Form Annotation Configuration Webapp. All URLs are restricted to valid users except the login, logoff, and style sheet. Only admins have the ability to delete a record. A non-admin doesn't see the link on the search page to delete a record and also calling the delete method on the DAO is restricted to admins. DavidWinterfeldt
Basic Webapp Internationalization 2.5 Creating a basic webapp that will handle UTF-8 characters from form input and also have internationalized messages. DavidWinterfeldt
Simple Spring MVC Form Annotation Configuration Webapp 2.5 Simple Spring MVC form using annotation-based configuration. The webapp has basic create, update, delete, and search functionality for a person form. The form basically just has a hidden id (primary key), first name, and last name fields. Tiles is implemented with Dynamic Tiles Spring MVC Module, Hibernate, and internationalized messages are configured, but this example will focus on explaining the MVC configuration. DavidWinterfeldt
Simple Spring Transactional JUnit 4 Test 2.5 Simple Spring Transactional JUnit 4 Test of a Hibernate transaction. DavidWinterfeldt
Hibernate Transaction Annotation Configuration 2.5 Creating basic transaction using annotations with Spring for Hibernate. DavidWinterfeldt
One to Many Hibernate Annotation Configuration 2.5 A simple example using a One to Many relationship in Hibernate with an Annotation configuration to find, save, and update a record. DavidWinterfeldt
One to Many Hibernate XML Configuration 2.5 A simple example using a One to Many relationship in Hibernate with an XML configuration to find, save, and update a record. DavidWinterfeldt
Simple Hibernate XML Configuration 2.5 A simple example using Hibernate with an XML configuration to find, save, and update a record. DavidWinterfeldt
Spring by Example Util's Logger BeanPostProcessor 2.5 The Spring by Example Util module has different logger BeanPostProcessors to dynamically inject a logger based on reflection, interfaces, or annotations. Many loggers are defined with a static reference to the a class for each class and a developer cuts & pastes each logger definition. This can be error prone and the Logger BeanPostProcessors help deal with this problem. DavidWinterfeldt
Spring by Example Util's HttpClientTemplate 2.5 The Spring by Example Util module has HttpClientTemplate which uses Apache's HttpClient to process HTTP requests and receive the data as a String, InputStream, or byte[]. DavidWinterfeldt
Spring by Example Util's HttpClientOxmTemplate 2.5 The Spring by Example Util module has HttpClientOxmTemplate which uses Apache's HttpClient to process HTTP requests and Spring Web Service's OXM to marshall and unmarshall the requests. DavidWinterfeldt
Simple Spring JDBC Template 2.5 A simple example using SimpleJdbcTemplate. DavidWinterfeldt
Spring by Example JCR Module 2.5 The Spring by Example JCR module uses Spring Modules JCR (Java Content Repository) module. Currently the utilities provide a way to recurse through the repositories nodes using JcrTemplate and a custom node callback for each matching node found while recursing the repository. This example uses Apache Jackrabbit for the Java Content Repository which is the reference implementation for JSR-170. DavidWinterfeldt
SLF4J Auto Injection of a Logger into beans 2.5 This example shows how to auto-inject a org.slf4j.Logger into any bean that has a method setLogger accepting a logger using a BeanPostProcessor. TimVoet
AspectJ Load-time Weaving in Spring 2.5 This example shows using Spring with AspectJ's Load-time Weaving (LTW) to gather statistics. DavidWinterfeldt
Spring Modules JCR Node Creation & Retrieval 2.5 This example shows how to create and retrieve nodes and files (content nodes) using Spring Modules JCR (Java Content Repository (JSR-170)) module. DavidWinterfeldt
Dynamic Tiles Spring MVC Module 2.5 The Dynamic Tiles 2 module dynamically renders a Tiles 2 template with Spring MVC. Any request coming in mapped for Tiles processing will use the default template and dynamically insert the body based on the URL. DavidWinterfeldt
Simple Tiles Spring MVC Example 2.5 This is a simple example showing how to setup Spring MVC to use Tiles 2. Any request coming in mapped for Tiles processing will attempt to find a Tiles definition that matches the request and then render it. DavidWinterfeldt
Custom Thread Scope 2.5 The Spring by Example Custom Thread Scope module is a custom scope implementation for providing thread scoped beans. DavidWinterfeldt
Spring Web MVC Locale Change 2.0 Simple example showing one way to setup internationalization. TimVoet

DB Examples

Topic Spring Version Description Creator
Spring by Example JDBC 2.5 The Spring by Example JDBC module has some utilities to help creating and initializing a database. There is an extension of SimpleDriverDataSource from Spring, which doesn't pool connections, that can be configured to run scripts once the class is initialized and another one based on Commons DBCP BasicDataSource. The script processor that they use can also be used separately. DavidWinterfeldt
One to Many JPA Hibernate Configuration 2.5 One to Many JPA configuration using Hibernate that can to find, save, and update a record. There is a Person that has a one-to-many relationship to Address. This example is very similar to One to Many Hibernate Annotation Configuration example since that example was already using javax.persistence annotations to configure the Person and Address beans. DavidWinterfeldt
Simple Spring Transactional JUnit 4 Test 2.5 Simple Spring Transactional JUnit 4 Test of a Hibernate transaction. DavidWinterfeldt
Hibernate Transaction Annotation Configuration 2.5 Creating basic transaction using annotations with Spring for Hibernate. DavidWinterfeldt
One to Many Hibernate Annotation Configuration 2.5 A simple example using a One to Many relationship in Hibernate with an Annotation configuration to find, save, and update a record. DavidWinterfeldt
One to Many Hibernate XML Configuration 2.5 A simple example using a One to Many relationship in Hibernate with an XML configuration to find, save, and update a record. DavidWinterfeldt
Simple Hibernate XML Configuration 2.5 A simple example using Hibernate with an XML configuration to find, save, and update a record. DavidWinterfeldt
Simple Spring JDBC Template 2.5 A simple example using SimpleJdbcTemplate. DavidWinterfeldt

Web Examples

Topic Spring Version Description Creator
Simple Spring Web Services 2.5 A very simple example of using Spring Web Services 1.5.x with JAXB for marshalling and unmarshalling requests. A JAXB plugin for Maven is used to generate the JAXB beans from and XSD and the XSD is reused to generate a WSDL. The response from the server sends a person list, but could easily be modified to retrieve person based on an ID. DavidWinterfeldt
Simple GWT Spring Webapp 2.5 This enhances the Spring Web Flow Subflow Webapp by using GWT (Google Web Toolkit) version 1.5-RC1 for a GWT table widget on the search page. The example also uses Spring JS to submit the person form by using Spring.remoting.submitForm to only update the content div. Dynamic Tiles Spring MVC Module? (version 1.1) has been updated to support rendering Tiles fragments like AjaxTilesView and FlowAjaxTilesView in Spring JS and Spring Web Flow. DavidWinterfeldt
Spring Web Flow Subflow Webapp 2.5 A Spring Web Flow 2.0 example using a flow to create and edit a Person and a subflow to create and edit a Person's Addresses. A Spring MVC annotation-based controller still handles search and deleting Person records. The example is built on Simple Spring Web Flow Webapp which can be referred to if necessary. DavidWinterfeldt
Simple Spring Web Flow Webapp 2.5 A very simple Spring Web Flow 2.0 example using a flow to create and edit a Person. A Spring MVC annotation-based controller still handles search and deleting records. The example is built on Simple Spring MVC Form Annotation Configuration Webapp and Simple Spring Security Webapp which can be referred to for better explanations of Spring MVC Annotations and Spring Security. DavidWinterfeldt
Simple Spring Security Webapp 2.5 Simple Spring Security 2.0 example securing a webapp based on the Simple Spring MVC Form Annotation Configuration Webapp. All URLs are restricted to valid users except the login, logoff, and style sheet. Only admins have the ability to delete a record. A non-admin doesn't see the link on the search page to delete a record and also calling the delete method on the DAO is restricted to admins. DavidWinterfeldt
Basic Webapp Internationalization 2.5 Creating a basic webapp that will handle UTF-8 characters from form input and also have internationalized messages. DavidWinterfeldt
Simple Spring MVC Form Annotation Configuration Webapp 2.5 Simple Spring MVC form using annotation-based configuration. The webapp has basic create, update, delete, and search functionality for a person form. The form basically just has a hidden id (primary key), first name, and last name fields. Tiles is implemented with Dynamic Tiles Spring MVC Module, Hibernate, and internationalized messages are configured, but this example will focus on explaining the MVC configuration. DavidWinterfeldt
Dynamic Tiles Spring MVC Module 2.5 The Dynamic Tiles 2 module dynamically renders a Tiles 2 template with Spring MVC. Any request coming in mapped for Tiles processing will use the default template and dynamically insert the body based on the URL. DavidWinterfeldt
Simple Tiles Spring MVC Example 2.5 This is a simple example showing how to setup Spring MVC to use Tiles 2. Any request coming in mapped for Tiles processing will attempt to find a Tiles definition that matches the request and then render it. DavidWinterfeldt
Spring Web MVC Locale Change 2.0 Simple example showing one way to setup internationalization. TimVoet