spring-framework
概述
Halo框架在基础构件区域引入了 spring-framework 作为应用的对象容器,同时借助其依赖注入特性,AOP等增强特性来组装新模块和功能。于此,建议开发人员尽可能的使用在spring-framework
框架规范下的构件特性。
特性浏览
Halo的
doritos.3.X
版本中,使用的是spring-framework
的5.X版本。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
装配
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.xml
或halo-xxx-starter
来实现)之外,还会读取classpath
根目录下所有applicationContext-*.xml
文件。
3. 基于java-config
编写
XXXConfiguration
代码文件@Configuration public class CustomConfiguration { @Bean public SoapService soapService() { return new SoapServiceImpl(); } }
Last updated