The Spring framework , created by Rod Johnson, is an extremely powerful Inversion of control(IoC) framework to helps decouple your project components’ dependencies.
In this tutorials, it’s provides many step by step examples and explanations on using Spring framework.
Happy learning Spring. :)
Spring Quick Start
Let’s go through a quick start to understand the Spring framework.
- Quick start Maven + Spring Example
A quick start to create a project with Maven and Spring. - Spring loosely coupled example
An output generator example to develop with 3 methods, call it directly, via helper class and via Spring framework. See the different among these three methods and how Spring framework make it loosely coupled.
Dependency Injection (DI)
Dependency Injection (DI) design pattern is used to define the object dependencies between each other.
- Spring Dependency Injection (DI)
How Spring apply the Dependency Injection (DI) design pattern via Setter Injection and Constructor Injection. - Type Ambiguities Issue in Constructor injection
The constructor injection argument type ambiguities issue is always happened in a bean which contains multiple constructor methods with many arguments.
Bean Configuration
All the classes you need to use in Spring Ioc container are consider “bean”, and declared it in Spring bean configuration file.
- Define bean properties in Spring
There are three ways to e ways to define the bean properties in Spring. - Bean reference in Spring
How beans can access to each other by specify the bean references in the same or different bean configuration file. - Load multiple Spring Bean configuration files
Developers always categories different modules to different bean configuration files, here’s a tip to show how to load multiple Spring bean configuration files. - Inner bean examples
Whenever a bean is used for one particular property only, it’s always advise to declared it as an inner bean. - Bean properties dependency checking
Spring comes with 4 dependency checking modes to make sure all the required properties have been set in bean. - Bean properties dependency checking with @Required
Annotation
How to define properties dependency checking in annotation mode. - Define custom @Required-style annotation
How to define a custom @Required-style annotation ,which is equivalent to @Required annotation. - Bean Scopes examples
Bean scope is used to decide which type of bean instance should be return to the caller.
Advance Bean Configuration
Some advance topic in bean configuration.
- Bean Configuration Inheritance
A child bean or inherited bean will inherit the bean configuration, properties and some attributes from the parent bean. - Collections (List, Set, Map, and Properties) example
How to define collections type (List, Set, Map, and Properties) in Spring’s bean configuration file. - ListFactoryBean example
The ‘ListFactoryBean’ object provides developer a way to create a concrete List collection class (ArrayList and LinkedList) in Spring’s bean configuration file. - SetFactoryBean example
The ‘SetFactoryBean’ object provides developer a way to create a concrete Set collection class (HashSet and TreeSet) in Spring’s bean configuration file. - MapFactoryBean example
The ‘MapFactoryBean’ object provides developer a way to create a concrete Map collection class (HashMap and TreeMap) in Spring’s bean configuration file. - Assign a Date into bean property (CustomDateEditor)
Normally, Spring is not accept the date variable, here’s a tip to use CustomDateEditor to workaround it. - Auto Scanning Components
How to automatic scan, detect and instantiate your beans or components from project class path. - Filtering Components in Auto Scanning
How to filtering certain components in auto scanning mode. - PropertyPlaceholderConfigurer example
Use PropertyPlaceholderConfigurer to externalize the deployment details into a properties file, and access from bean configuration file via a special format – $variable.
Bean Initialization & Destruction
It allow the bean to perform certain actions upon initialization and destruction.
- InitializingBean and DisposableBean example
Implement both InitializingBean and DisposableBean interface for initialization and destruction feature. - init-method and destroy-method example
Define init-method and destroy-method in bean configuration file for initialization and destruction feature. - @PostConstruct and @PreDestroy example
Annotation version for initialization and destruction feature.
Auto-Wire Bean
Spring comes with 5 ‘auto-wiring’ modes to wire or match the beans automatically.
- Auto-Wiring Beans in XML
Examples to show how to define ‘auto-wiring’ modes in bean configuration file. - Auto-Wiring Beans in annotation @Autowired
Examples to show how to define ‘auto-wiring’ modes in annotation.
Spring AOP (Aspect-oriented programming)
The Spring AOP modularize cross-cutting concerns in aspects. Put it simple, 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 proxies object for your beans automatically, useful to avoid create many duplicated proxy objects.
Spring JDBC Support
Spring provides many helper classes to simplify the overall JDBC database operation.
- Spring + JDBC example
Example to show how to integrate Spring and JDBC. - Spring + 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 few examples to show how to use JdbcTemplate query() methods to query or extract data from database. - SimpleJdbcTemplate Querying examples
More user friendly and simple way to query or extract data from database. - 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 batchUpdate() example
A batchUpdate() example to show how to perform the batch insert operations. - SimpleJdbcTemplate batchUpdate() example
Another batch update example with SimpleJdbcTemplate, a java5-friendly supplement to JdbcTemplate.
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
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 sent 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
Article about how Spring schedule a job with JDK timer. - Spring + Quartz scheduler example
Article about how Spring schedule a job with Quartz framework. - Spring + Struts + Quartz scheduler example
Integrate Spring with Struts and schedule a job with Quartz framework.
Integrating Spring with Other Web Frameworks
Spring integrate with other web frameworks.
- Spring dependency injection in serlvet 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 MVC framework.
Spring Multi Languages Support
Spring comes with ‘Resource bundle’ classes to support different languages or locales.
- 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.
Spring Misc
- 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 file system , classpath or URL.
Spring IDE
Spring IDE is a very useful graphical user interface tool for Spring Framework. The Spring code assist is my favor feature, i think no one can memorize all the Spring keywords.
- Install Spring IDE in Eclipse
Article about how to install Spring IDE in Eclipse.
Spring Common Errors
Some Spring common error messages.
- ClassNotFoundException : org.springframework.web.context.ContextLoaderListener
- Cannot proxy target class because CGLIB2 is not available
home
Info
sitemap




