Spring (1) -- For Simplify Java Development

本文介绍了Spring框架的主要特性,包括依赖注入(DI)和面向切面编程(AOP)。通过四大策略简化Java开发:使用纯Java对象实现轻量级开发、通过依赖注入减少耦合、声明式编程以及模板消除重复代码。
摘要由CSDN通过智能技术生成

Spring’s primary features are dependency injection (DI) and aspect-oriented programming (AOP).

For simplify Java development, spring employs four key strategies:
1. Lightweight and minimally invasive development with plain old Java objects (POJOs).
2. Loose coupling through DI and interface orientation.
3. Declarative programming through aspects and common conventions.
4. Eliminating bolierplate code with aspects and templates.

Dependency injection

Coupling is a two-headed beast, on the one hand, tightly coupled code is difficult to test, difficult to resure and difficult to understand, on the other hand, coupling is necessary – in order to do anything useful, classes need to know about each other somehow.

With DI, objects are given their dependencies at creation time by some third party that coordinates each objects in the system.

The act of creating associations between aplication components is commonly refered to as wiring.

In a spring application, the spring application context is fully responsible for the creation of and wiring of the objects that make up the application. Spring comes with several implementations of its application context, each primarily differing only in how it loads its configuration.

Aspect-oriented programming

System are composed of several components, each responsible for a specific piece of functionality, but often these components also carry additional reponsibilities beyond their core functionality, such as logging, transaction management or security concern.

With AOP, you can then cover your core application with layers of functionality, these layers can be applied declaratively throughtout your application in a flexible manner without your core application even knowing they exist.

First, you need to declare a bean, then you refer to that bean in the element. Second, you define a pointcut element with an expression attribute set to select where the advice should be applied, the expression syntax is AspectJ’s pointcut expression language.

Template

Many activities require similar boilerplate code, JDBC, JMS, JNDI and the consumption of REST services often involve a lot of commonly repeated code.

Spring seeks to eliminate boilerplate code by encapsulating it in templates.

Spring container

In a Spring application, objects are created, are wried together, and live in the Spring container.

The container is at the core of the Spring framework.

There’s no single Spring container, Spring comes with several container implementations that can be categorized into two distinct type: Bean factories are the simplest containers, providing basic support for DI; Application context build on the nontion of a bean factory by providing application-framework services.

Application context –
XML: ClassPathXMLApplicationContext/FileSystemXMLApplicationContext
Java-Base: AnnotationConfigApplicationContext

Spring bean’s life begin with creation and remain in the application context until the application context is destroyed.

An empty container doesn’t contain anything unless you put something in it.

Spring Modules

For Spring 4.0, these modules can be arranged into six categories of functionality.

Core Spring container
Core/Beans/Context/Expression/Context support
Aspect-oriented programming
AOP/Aspects
Data access & integration
JDBC/ORM/OXM/Transaction/Messaging/JMS
Web and remoting
Web/Web servlet/Web portlet/Websocket
Instrumentation
Instrument/Instrument Tomcat
Testing
Test

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值