首页 > 其他分享 >AS3 IOC框架Spring Actionscript 的使用总结

AS3 IOC框架Spring Actionscript 的使用总结

时间:2022-12-27 19:01:24浏览次数:63  
标签:AS3 Spring context Actionscript var IOC public


Spring Actionscript 是众多围绕依赖注入提供解决方案的Flex控制反转框架之一

AS3 下经典的IOC框架有Spring ActionScript、Parsley、Flicc和Swiz,由于我对JAVA spring IOC机制较为熟悉,所以选择了 Spring ActionScript。

主要有XML配置(XML)和注释元数据(Metadata)配置两种方式,下面一一介绍,例子是基于spring AS 2.0.1版本展开的。--流子

1.从​​Spring Actionscript 主页​​下载依赖包 

spring-actionscript-core-X.X.X.swc

spring-actionscript-flex-X.X.X.swc

另有as3commons依赖包需要下载。建议下载这个 

​Spring Actionscript X.X.X Full​​ (with dependencies and Flex extensions)

2.1 XML配置方式

配置文件application-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<objects xmlns="http://www.springactionscript.org/schema/objects"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springactionscript.org/schema/objects
http://www.springactionscript.org/schema/objects/spring-actionscript-objects-2.0.xsd">
<object id="ConfigManager" class="com.yimi.fairy.client.ConfigManager"
init-method="initialize">
<!--<constructor-arg ref="authenticationService"/> 构造函数时引入 -->
</object>
<object id="RoleManager" class="com.yimi.fairy.client.service.role.RoleManager"
init-method="initialize">
<property name="configManager" ref="ConfigManager" />
</object>
<object id="ResourceManager" class="com.yimi.fairy.client.res.ResourceManager"></object>
<object id="JobManager" class="com.yimi.fairy.client.job.JobManager"></object>
<object id="RoleDataTemplateManager" class="com.service.role.RoleDataTemplateManager">
<constructor-arg ref="ResourceManager"/>
</object>
</objects>

程序载入:

var context:XMLApplicationContext=new XMLApplicationContext("application-context.xml");
context.addEventListener(Event.COMPLETE, this.handleComplete);
context.load();

对容器中对象读取:

var configManager:ConfigManager=context.getObject("ConfigManager");

2.2 注释元数据(Metadata)配置方式

优点:把application-context.xml 完全干掉,完全通过注释方式实现。它是对加载进来的SWF文件进行类扫描把[Component] 或者[Configuration] 读取并解析进IOC容器。


首先,要添加编译参数 -keep-as3-metadata+=Component,Invoke,Inject,Autowired


程序载入


var rootViews:Vector.<DisplayObject> = new <DisplayObject>[display];
var context:MetadataApplicationContext= new MetadataApplicationContext(rootViews);
context.addEventListener(Event.COMPLETE, this.handleComplete);
context.load();

对象配置:

[Component(id="roleDataTemplateManager",initMethod="initialize")]
public class RoleDataTemplateManager implements IResourceLoader
{
[Autowired]
public var resourceManager:ResourceManager;
public function initialize():void
{
resourceManager.register(this);
}
}

注意注入进去的对象必须是public,否则注不进去。


对象读取:

var configManager:ConfigManager=context.getObject("configManager");

2.3 如何注入第三方库中的对象

创建一个对象,比如AppConfig


[Configuration]
public final class AppConfig {
public var stageAutowireProcessor:DefaultAutowiringStageProcessor;
public var eventHandlerMetadataProcessor:EventHandlerMetadataProcessor;
public var routeEventsMetadataProcessor:RouteEventsMetaDataProcessor;
}


Reference:

​Spring AS Document​


标签:AS3,Spring,context,Actionscript,var,IOC,public
From: https://blog.51cto.com/u_4176761/5973360

相关文章

  • AS3使用过程中问题总结
    1.Starling项目启动时报错Thisapplicationisnotcorrectlyembedded(wrongwmodevalue)这个其实是Flash报的“ErrorEvent:。text=Error#3702:Context3D不可用”错......
  • Spring安全和角度(二)
    使用OAuth2进行单点登录在本节中,我们继续我们的讨论如何使用弹簧安全跟角在“单页应用程序”中。在这里,我们展示如何使用春季安全密钥䋰春云将我们的API网关扩展到后端......
  • SpringBoot - 自定义拦截器HandlerInterceptor
    1.实现HandlerInterceptor接口/***自定义拦截器*/publicclassMyInterceptorimplementsHandlerInterceptor{@OverridepublicbooleanpreHandle(Htt......
  • SpringBoot - 转换器Convert与SpringBoot支持的返回类型
    1.自定义转换器@Configuration(proxyBeanMethods=false)publicclassAppConfig{@BeanpublicWebMvcConfigurergetWebMvcConfigurer(){returnn......
  • Spring Boot Docker 应用程序
    许多人使用容器来包装他们的SpringBoot应用程序,构建容器并不是一件简单的事情。这是针对SpringBoot应用程序开发人员的指南,容器并不总是开发人员的良好抽象。它们迫使......
  • Kubernetes 上的Spring
    在构建在云中运行的Java应用程序时,弹簧和弹簧靴显然是最受欢迎的.同样越来越明显的是,Docker和Kubernetes等技术在春季社区中发挥重要作用.将SpringBoot应用程序打包在......
  • 使用 Spring 构建 REST 服务
    REST已迅速成为在Web上构建Web服务的事实标准,因为它们易于构建和使用。关于REST如何适应微服务领域,还有更大的讨论,但是在本教程中,让我们只看一下构建RESTful服务。......
  • springAMQP
                                                       ......
  • SpringBoot - 静态资源的默认存放位置与修改默认存放位置,默认配置文件加载的路径
    1.静态资源文件路径静态资源文件路径是指用户可以直接通过游览器访问到文件的存放位置。按照优先级有一下4个路径:classpath:/META-INF/resources/classpath:/resources/......
  • java.lang.IllegalStateException: Method has too many Body parameters: public abs
    Errorcreatingbeanwithname'cn.com.taiji.fzy.indidocxToken.feign.IndidocxTokenFeignClient':Unexpectedexceptionduringbeancreation;nestedexceptionis......