The Spring framework , created by Rod Johnson, is an extremely powerful Inversion of control(IoC) framework to help decouple your project components’ dependencies.

In this series of tutorials, it’s provides many step by step examples and explanations on using the Spring framework.

New Spring 3.0 Tutorials (23/06/2011)
Added many Spring 3.0 tutorials on using Spring EL, JavaConfig, AspectJ and Spring Object/XML mapping (oxm). For what’s new in Spring 3.0, you can refer to this official Spring 3.0 references.

Spring Quick Start

Quick start to understand the basic of Spring framework development.

Spring JavaConfig (Spring 3.0)

Spring 3.0 supported JavaConfig, now you can use annotations to do the configuration in Spring.

Spring Dependency Injection (DI)

How Spring to do dependency Injection (DI) to manage object dependencies.

Bean Basic

All the classes you need to use in Spring Ioc container are considered “bean”, and declared in a Spring bean configuration file or via annotation.

  • Spring bean reference example
    How beans access to each other by specify the bean references in the same or different bean configuration file.
  • Inject value into bean properties in Spring
    Three ways to inject value into bean properties.
  • Load multiple Spring bean configuration file
    Developers always categorize different bean configuration files in different modules folder, here’s a tip to show you how to load multiple Spring bean configuration files.
  • Spring inner bean examples
    Whenever a bean is used for one particular property only, it’s always advised to declare it as an inner bean.
  • Spring bean scopes examples
    Bean scope is used to decide which type of bean instance should be return from the Spring container back to the caller.
  • Spring Collections (List, Set, Map, and Properties) example
    Example to inject values into collections type (List, Set, Map, and Properties).
  • ListFactoryBean example
    Create a concrete List collection class (ArrayList and LinkedList), and inject it into bean property.
  • SetFactoryBean example
    Create a concrete Set collection class (HashSet and TreeSet), and inject it into bean property.
  • MapFactoryBean example
    Create a concrete Map collection class (HashMap and TreeMap), and inject it into bean property.
  • Spring inject Date into bean property – CustomDateEditor
    Normally, Spring is accepting date variable, here’s a tip to use CustomDateEditor to work around it.
  • Spring PropertyPlaceholderConfigurer example
    Externalize the deployment details into a properties file, and access from a bean configuration file via a special format – ${variable}.
  • Spring bean configuration inheritance
    Inheritance is very useful for a bean to share common values, properties or configuration.
  • Spring dependency checking
    Spring comes with 4 dependency checking modes to make sure the required properties have been set in bean.
  • Spring dependency checking with @Required Annotation
    Dependency checking in annotation mode.
  • Custom @Required-style annotation
    Create a custom @Required-style annotation ,which is equivalent to @Required annotation.
  • Bean InitializingBean and DisposableBean example
    Perform certain actions upon bean initialization and destruction. (interface)
  • Bean init-method and destroy-method example
    Perform certain actions upon bean initialization and destruction. (XML)
  • Bean @PostConstruct and @PreDestroy example
    Perform certain actions upon bean initialization and destruction. (Annotation)
  • Spring Profiles example
    Spring @Profile allow developers to register beans by condition.

Spring Expression Language (Spring 3.0)

Spring 3.0 introduces features rich and powerful expression language known as Spring expression language, or Spring EL.

  • Spring EL hello world example
    Quick start to use the Spring expression language (EL).
  • Spring EL bean reference example
    Reference bean, bean property using a dot (.) symbol.
  • Spring EL method invocation example
    Call bean method in directly.
  • Spring EL operators example
    Spring EL supports most of the standard relational, logical and mathematical operators.
  • Spring EL ternary operator (if-then-else) example
    Conditional check , if else then.
  • Spring EL Arrays, Lists, Maps example
    Works with Map and List.
  • Spring EL regular expression example
    The regular expression to evaluate the condition.
  • Test Spring EL with ExpressionParser
    Show you how to test Spring El easily.

Spring Auto Component Scanning

Spring is able to scan, detect and register your bean automatically.

Spring AutoWiring Bean

Spring ‘auto-wiring’ modes to wire or beans automatically, both in XML and annotation.

Spring AOP (Aspect-oriented programming)

The Spring AOP modularize cross-cutting concerns in aspects. Put it simply, an interceptor to intercept some methods.

  • Spring AOP Example – Advice
    Examples and explanations about different types of Spring’s advices.
  • Spring AOP Example – Pointcut , Advisor
    Examples and explanations about different types of Spring’s Pointcut and Advisor.
  • Spring AOP interceptor sequence
    The sequence of the AOP interceptor will affect the functionality.
  • Auto proxy creator example
    An auto proxy creator example to create proxy object for your beans automatically, useful to avoid creating many duplicated proxy objects.

Spring AOP + AspectJ framework

AspectJ supported since Spring 2.0, more flexible and powerful. However, this example is demonstrated in Spring 3.0.

  • Spring AOP + AspectJ annotation example (Spring 3.0)
    An example to show you how to integrate AspectJ annotation with Spring framework.
  • Spring AOP + AspectJ in XML configuration example (Spring 3.0)
    Spring AOP with AspectJ in XML base configuration.

Spring Object/XML Mapper (Spring 3.0)

In Spring 3.0, Object to XML mapping (OXM) is moved from the Spring Web Services to the core Spring Framework.

  • Spring Object/XML mapping example
    Spring oxm + castor, convert Object to XML and vice verse.

Spring JDBC Support

Spring provides many helper classes to simplify the overall JDBC database operation.

  • Spring + JDBC example
    An example to show how to integrate Spring and JDBC.
  • JdbcTemplate + JdbcDaoSupport example
    Example to use Spring’s JdbcTemplate and JdbcDaoSupport classes to simplify the overall JDBC database operation processes.
  • JdbcTemplate Querying examples
    Here are a few examples to show how to use JdbcTemplate query() methods to query or extract data from database.
  • JdbcTemplate batchUpdate() example
    A batchUpdate() example to show how to perform the batch insert operations.
  • SimpleJdbcTemplate Querying examples
    More user friendly and simple way to query or extract data from database.
  • SimpleJdbcTemplate batchUpdate() example
    Another batch update example with SimpleJdbcTemplate, a java5-friendly supplement to JdbcTemplate.
  • Named Parameters examples in SimpleJdbcTemplate
    An example to show how to use named parameter as SQL parameter values, and this is only supported in SimpleJdbcTemplate.
  • JdbcTemplate queryForInt() is Deprecated

Spring Hibernate Support

Spring comes with many handy classes to support Hibernate ORM framework.

  • Maven + Spring + Hibernate + MySql Example
    A simple project of using Spring and Hibernate.
  • Maven + (Spring + Hibernate) Annotation + MySql Example
    A simple project of using Spring and Hibernate (annotation version).
  • Spring AOP transaction management in Hibernate
    An example to show how to manage the Hibernate transaction with Spring AOP.
  • Struts + Spring + Hibernate integration
    Example to integrate Spring with Struts and Hibernate framework.

Spring E-mail Support

Spring’s provides MailSender to send email via JavaMail API.

  • Sending E-mail via MailSender
    Example to use Spring’s MailSender to send an email via Gmail SMTP server.
  • E-mail template in bean configuration file
    Hard-code all the email properties and message content in the method body is not a good practice, you should consider define the email message template in the Spring’s bean configuration file.
  • Sending e-mail with attachment
    Example to use Spring to send an email that has attachments.

Spring Scheduling Support

Spring has very good support in both JDK timer and Quartz framework.

  • Spring + JDK Timer scheduler example
    An article about how Spring schedules a job with JDK timer.
  • Spring + Quartz scheduler example
    An article about how Spring schedules a job with Quartz framework.
  • Spring + Struts + Quartz scheduler example
    Integrate Spring with Struts and schedule a job with Quartz framework.

Spring Caching Support

Integrating Spring with Other Web Frameworks

Spring integrates with other web frameworks.

  • Spring dependency injection in the servlet session listener
    Spring comes with a “ContextLoaderListener” listener as a generic way to enable the Spring dependency injection in session listener and almost all other web framework.
  • Struts + Spring integration
    Example to integrate Spring with Struts 1.x framework.
  • Struts 2 + Spring integration example
    Example to integrate Spring with Struts 2 framework.
  • JSF 2.0 + Spring integration example
    Example to integrate JSF 2.0 with Spring framework.
  • JSF 2.0 + Spring + Hibernate integration example
    Example to integrate JSF 2.0 + Spring + Hibernate framework together.
  • Wicket + Spring integration example
    Example to integrate Wicket with Spring framework.
  • Struts 2 + Spring + Quartz scheduler integration example
    Example to integrate Spring + Struts 2 + Quartz.
  • Struts 2 + Spring + Hibernate integration example
    Example to integrate Spring + Struts 2 + Hibernate.
  • RESTEasy + Spring integration example
    Examples to inject Spring beans into JBoss RESTEasy

Spring FAQs

  • Install Spring IDE in Eclipse
    An article about how to install Spring IDE in Eclipse.
  • Resource bundle with ResourceBundleMessageSource example
    ResourceBundleMessageSource is the most common class to resolve text messages for different locales.
  • Access MessageSource in bean (MessageSourceAware)
    An example to show how to get the MessageSource in a bean via MessageSourceAware interface.
  • Resource loader with getResource() example
    Spring’s resource loader provides a very generic getResource() method to get the resources like (text file, media file, image file…) from the file system , classpath or URL.

Spring Common Errors

Some Spring common error messages.

Spring Knowledge

Spring References

Leave a Reply

Your email address will not be published. Required fields are marked *