Spring对Java语言的支持
java5
| 语法特性 | Spring支持的版本 | 代表实现 |
|---|---|---|
| Annotation | 1.2+ | @Transactional |
| Enumeration | 1.2+ | Propagation |
| for-each | 3.0+ | AbstractApplicationContext |
| Auto Boxing | 3.0+ | |
| Generic | 3.0+ | ApplicationListener |
java6
| 语法特性 | Spring支持的版本 | 代表实现 |
|---|---|---|
| 接口@Override | 4.0+ |
java7
| 语法特性 | Spring支持的版本 | 代表实现 |
|---|---|---|
| Diamond语法 | 5.0+ | DefaultListableBeanFactory |
| try-with-resources语法 | 5.0+ | ResourceBundleMessageSource |
java8
| 语法特性 | Spring支持的版本 | 代表实现 |
|---|---|---|
| Lambda语法 | 5.0+ | PropertyEditorRegistrySupport |
Spring对jdk api实践
java5
| API | Spring支持的版本 | 代表实现 |
|---|---|---|
| XML处理(DOM,SAX...) | 1.0+ | XmlBeanDefinitionReader |
| JMX | 1.2+ | @ManagedResource |
| Instrumentation | 2.0+ | InstrumentationSavingAgent |
| JUC | 3.0+ | ThreadPoolTaskScheduler |
| Formatter | 3.0+ | DateFormatter |
java6
| API | Spring支持的版本 | 代表实现 |
|---|---|---|
| JDBC4.0(JSR 221) | 1.0+ | JdbcTemplate |
| Common Annotations(JSR 250) | 2.5+ | CommonAnnotationBeanPostProcessor |
| JAXB2.0 (JSR 222) | 3.0+ | Jaxb2Marshaller |
| Scripting in JVM(JSR 223) | 4.2+ | StandardScriptFactory |
| 可插拔注解处理API(JSR 269) | 5.0+ | @Indexed |
| Java Compiler API(JSR 199) | 5.0+ | TestCompiler(单元测试) |
java7
| API | Spring支持的版本 | 代表实现 |
|---|---|---|
| Fork/Join框架(JSR 166) | 3.1+ | ForkJoinPoolFactoryBean |
| NIO(JSR 203) | 4.0+ | PathResource |
java8
| API | Spring支持的版本 | 代表实现 |
|---|---|---|
| Date And Time(JSR 310) | 4.0+ | DateTimeContext |
| 可重复Annotations(JSR 337) | 4.0+ | @PropertySources |
| Stream API (JSR 335) | 4.2+ | StreamConverter |
| CompletableFuture(JUC) | 4.2+ | CompletableToListenableFutureAdapter |
Spring对java EE API整合
java ee web技术相关
| API | Spring支持的版本 | 代表实现 |
|---|---|---|
| Servlet+jsp(JSR 035) | 1.0+ | DispatcherServlet |
| JSTL(JSR 052) | 1.0+ | JstlView |
| JavaServer Faces(JSR 127) | 1.1+ | FacesContextUtils |
| Portlet(JSR 168) | 2.0-4.2 | DispathcerPortlet |
| SOAP(JSR 067) | 2.5+ | SoapFaultException |
| WebServices(JSR 109) | 2.5+ | CommonAnnotationBeanPostProcessor |
| WebSocket(JSR 356) | 4.0+ | WebSocketHandler |
java ee data access相关
| API | Spring支持的版本 | 代表实现 |
|---|---|---|
| JDO(JSR 12) | 1.0-4.2 | JdoTemplate |
| JTA(JSR 907) | 1.0+ | JtaTransactionManager |
| jpa(EJB JSR 220) | 2.0+ | JpaTransactionManager |
| java caching api(JSR 168) | 3.2+ | JCacheCache |
java ee bean相关
| API | Spring支持的版本 | 代表实现 |
|---|---|---|
| jms(JSR 914) | 1.1 | jmstemplate |
| ejb 2.0(JSR 19) | 1.0+ | abstractstatefulsessionbean |
| dependency injection for java(JSR 330) | 2.5+ | autowiredannotationbeanpostprocessor |
| bean validation(JSR 303) | 3.0+ | LocalValidatorFactoryBean |
Spring对设计模式的支持
| 设计模式 | 代表实现 | 备注 |
|---|---|---|
| 工厂模式 | BeanFactory, 工厂方法创建Bean | |
| 单例模式 | Bean Scope默认是单例 | |
| 原型模式 | Bean Scope可以设置为prototype | |
| 代理模式 | JdkDynamicAopProxy, CglibAopProxy | |
| 委托模式 | DispatcherServlet, BeanDefinitionParserDelegate | |
| 策略模式 | InstantiationStrategy,DefaultAopProxyFactory | DefaultAopProxyFactory#hasNoUserSuppliedProxyInterfaces动态决定使用什么策略实现aop |
| 模板模式 | JdbcTemplate, HttpServlet | JdbcTemplate基于callback |
| 适配器模式 | HandlerAdapter | DispatcherServlet里支持Controller注解,Controller接口, Servlet接口+xml配置的方式,需适配统一 |
| 装饰者模式 | HttpHeadResponseDecorator, TransactionAwareCacheDecorator | TransactionAwareCacheDecorator(在事务提交,回滚的时候对Cache的数据进行处理。) |
| 观察者模式 | ContextLoaderListener, ApplicationListener, ApplicationEvent,ApplicationContext | |
| 组合模式 | CacheManager, CompositeCacheManager | CompositeCacheManager中心节点,其余为子节点 |
| 职责链模式 | HandlerExecutionChain, Interceptor(拦截器), Filter | |
| 解释器模式 | spel |
Spring对设计思想的支持
- 约定优于配置
- 低侵入,松耦合
- 模块化,轻量级
- 封装,抽象(OOP)
- BOP
- AOP
- DI/DL
- IOC