spring-framework

概述

Halo框架在基础构件区域引入了 spring-framework 作为应用的对象容器,同时借助其依赖注入特性,AOP等增强特性来组装新模块和功能。于此,建议开发人员尽可能的使用在spring-framework框架规范下的构件特性。

特性浏览

  1. Halo的doritos.3.X版本中,使用的是spring-framework的5.X版本。

  2. Halo的coldnoodle.2.X版本中,使用的是spring-framework的4.X版本。

接下来,会对spring-framework包含的各种特性做简要描述,并表明是否在Halo框架内部使用,以及是否推荐开发者使用。

特性描述

halo使用程度

推荐使用指数

高度依赖

要求使用

轻度依赖

不推荐使用

轻度依赖

推荐使用

高度依赖

要求掌握

中度依赖

限制使用

未使用

推荐使用

未使用

不推荐使用

高度依赖

推荐使用

轻度依赖

要求使用

高度依赖

推荐使用

未使用

不推荐使用

轻度依赖

不推荐使用

中度依赖

推荐使用

未使用

推荐试用

轻度依赖

推荐试用

未使用

不推荐使用

未使用

不推荐使用

轻度依赖

推荐试用

未使用

不推荐使用

未使用

推荐试用

未使用

推荐试用

轻度依赖

推荐使用

关于spring-framework框架详细的帮助文档与使用手册,可以查阅 spring-framework 官方参考文档

代码管理约束

Halo框架不仅在内部大量使用了spring-framework的功能,也鼓励开发者充分利用spring-framework提供的特性。不过,从开发过程管理和代码规范管控的角度,Halo框架也对开发者在可以完全使用spring-framework的前提下,对代码组织方面做了一定约束。框架有限制的开放特定包路径的注解,以此来规范开发者的功能实现:

包路径

开放的注解

com.*.*.web

spring-mvc相关注解,@Autowired,@Resource,@Service

com.*.*.service.impl

@Autowired,@Resource,@Service, halo框架所有通过注解支持的功能

com.\*.\*.business

@Autowired,@Resource,@Service

com.\*.\*.dao

@Autowired,@Resource,@Repository

spring-bean装配

halo框架完全兼容spring-framework提供的spring-bean的装配和加载方式。

1. 基于运行时的注解识别

  • 声明spring-container托管的Service组件

    @Service("soapService")
    public class SoapServiceImpl implements SoapService{
        // 实现代码
    }
  • 声明spring-container托管的DAO组件

    @Repository("userInfoDao")
    public class UserInfoDaoImpl implements UserInfoDao{
        // 实现代码
    }
  • 声明spring-container托管的Controller组件

    @Controller
    @RequestMapping("users/soap")
    public class SoapServiceTestController {
        // 实现代码
    }

2. 基于XML配置

  • 配置spring-container托管的Service组件

    <bean id="testService" class="com.newcore.example.service.impl.TestServiceImpl"></bean>
  • 配置spring-container托管的DAO组件

    <bean id="testDao" class="com.newcore.example.dao.TestDao"></bean>

集成halo框架的应用系统,在启动时,spring-framework除了会载入halo框架预置好的依赖*.xml文件(可能通过web.xmlhalo-xxx-starter来实现)之外,还会读取classpath根目录下所有applicationContext-*.xml文件。

3. 基于java-config

  • 编写XXXConfiguration代码文件

    @Configuration
    public class CustomConfiguration {
      @Bean
      public SoapService soapService() {
          return new SoapServiceImpl();
      }
    }

Last updated