The Spring framework is based on the
Inversion of Control (IoC) principle, in which the objects define their own dependencies. Dependency Injection is a form of IoC. The container injects the dependencies when the bean is created. The dependency injection is implemented using the BeanFactory
and ApplicationContext
interfaces. The BeanFactory
interface is for managing beans and ApplicationContext
(WebApplicationContext
is used for a web application) is for configuring an application. BeanFactory
applies the IoC pattern to separate configuration and dependency specifications. The ApplicationContext
interface provides extended (extends) features to BeanFactory
.
The Spring MVC framework is based on the Model-View-Controller design pattern and is implemented using DispatcherServlet
. DispatcherServlet
fields requests and delegates them to a request handler using web request URI mapping provided by the @RequestMapping
annotation. The request handler or Controller returns Model
and View
using the ModelAndView
holder. In this chapter, we will create a Spring MVC application in Eclipse, compile and package the application using the Maven build tool, and deploy the application to WildFly 8.1. Subsequently, we will run the Spring application in a browser. In this chapter, we will cover the following topics:
We need to install the following software:
wildfly-8.1.0.Final.zip
from http://wildfly.org/downloads/.Set the JAVA_HOME
, JBOSS_HOME
, MAVEN_HOME
, and MYSQL_HOME
environment variables. Add %JAVA_HOME%/bin
, %MAVEN_HOME%/bin
, %JBOSS_HOME%/bin
, and %MYSQL_HOME/bin
to the PATH
environment variable.
Create a WildFly 8.1.0 runtime as discussed in Chapter 1, Getting Started with EJB 3.x. Create a MySQL data source with the JNDI name java:jboss/datasources/MySQLDS
as explained in Chapter 1, Getting Started with EJB 3.x.