Backend Development 20 min read

Spring Framework Overview: Core Concepts, IoC, Beans, AOP, MVC, and Configuration

This article provides a comprehensive overview of the Spring Framework, covering its version history, core features, dependency injection, bean definitions and scopes, annotation‑based configuration, data‑access support, aspect‑oriented programming, and the MVC request‑handling workflow, all illustrated with code examples.

Java Captain
Java Captain
Java Captain
Spring Framework Overview: Core Concepts, IoC, Beans, AOP, MVC, and Configuration

1. General Overview Spring Framework has become the standard Java web development framework. Major versions include Spring 2.5 (first with annotations, 2007), Spring 3.0 (Java 5 features, JEE6 support, 2009), and Spring 4.0 (full Java 8 support, 2013). It is an open‑source, lightweight, loosely‑coupled container that provides a layered architecture, supports POJO programming, and integrates with other frameworks such as Hibernate and EJB.

2. Dependency Injection (IoC) The Spring IoC container creates, configures, and manages bean lifecycles using dependency injection. Configuration can be supplied via XML, Java annotations, or Java code. Injection can be performed by constructor, setter, or (in Spring) by constructor and setter only. BeanFactory provides lazy loading, while ApplicationContext adds eager loading, internationalization, and annotation support.

3. Beans Beans are objects managed by the Spring IoC container. They can be defined using XML, annotations, or Java @Configuration classes. Spring supports five bean scopes: Singleton, Prototype, Request, Session, and Global‑session (portlet only). The bean lifecycle includes instantiation, property population, BeanNameAware, BeanFactoryAware, BeanPostProcessor callbacks, init‑method execution, and destruction callbacks.

interface Fruit { public abstract void eat(); } class Apple implements Fruit { public void eat() { System.out.println("Apple"); } } class Orange implements Fruit { public void eat() { System.out.println("Orange"); } } class Factory { public static Fruit getInstance(String className) { Fruit f = null; try { f = (Fruit) Class.forName(className).newInstance(); } catch (Exception e) { e.printStackTrace(); } return f; } } class Client { public static void main(String[] a) { Fruit f = Factory.getInstance("io.github.dunwu.spring.Apple"); if (f != null) { f.eat(); } } }

4. Annotation‑Based Configuration Using @Configuration and @Bean replaces XML bean definitions. Stereotype annotations include @Component (generic bean), @Controller (Web MVC controller), @Service (service layer), and @Repository (DAO with exception translation). @Required enforces mandatory property injection, @Autowired performs type‑driven injection, @Qualifier resolves ambiguity, and @RequestMapping maps HTTP requests to controller methods.

@Configuration public class StudentConfig { @Bean public StudentBean myStudent() { return new StudentBean(); } }

5. Data Access Spring DAO abstracts JDBC, Hibernate, JPA, etc., providing unified exception handling. JDBC templates include JdbcTemplate, SimpleJdbcTemplate, NamedParameterJdbcTemplate, SimpleJdbcInsert, and SimpleJdbcCall. Transaction management can be programmatic or declarative (annotation or XML). Supported ORM frameworks are Hibernate, iBatis, JPA, JDO, and OJB.

6. Aspect‑Oriented Programming (AOP) AOP introduces cross‑cutting concerns such as logging and security. Core concepts: Aspect (combines pointcut and advice), JoinPoint (method execution point), Advice (action taken at a join point). Advice types: @Before, @AfterReturning, @AfterThrowing, @After (finally), @Around. Spring AOP uses dynamic proxies (JDK or CGLIB) while AspectJ uses compile‑time weaving.

Advice + Target Object = Proxy

7. Spring MVC The DispatcherServlet acts as the front controller. It resolves the request URI, obtains a Handler via HandlerMapping, selects a HandlerAdapter, invokes the controller, and returns a ModelAndView. The ViewResolver then renders the view. WebApplicationContext extends ApplicationContext with web‑specific features.

(End of article)

JavaaopMVCIoCDependency InjectionSpring FrameworkBeans
Java Captain
Written by

Java Captain

Focused on Java technologies: SSM, the Spring ecosystem, microservices, MySQL, MyCat, clustering, distributed systems, middleware, Linux, networking, multithreading; occasionally covers DevOps tools like Jenkins, Nexus, Docker, ELK; shares practical tech insights and is dedicated to full‑stack Java development.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.