简体   繁体   English

android 应用中可以使用 Spring Framework 吗?

[英]Can the Spring Framework be used in android applications?

I am writing a android application which requires dependency injection in the data access API the application will need (I am implementing this API).我正在编写一个 android 应用程序,它需要在应用程序需要的数据访问 API 中进行依赖注入(我正在实现这个 API)。 I don't want to write the dependency injection manually.我不想手动编写依赖注入。 Therefore, I was thinking of using Spring.因此,我在考虑使用Spring。 I realize that there are two versions of spring.我意识到有两个版本的spring。 A regular version and a android version.一个普通版和一个安卓版。 Can the regular version be used in the android application cause I just want the dependency injection functionality and already have the files.是否可以在 android 应用程序中使用常规版本,因为我只想要依赖项注入功能并且已经有了这些文件。

Don't.别。 Spring is a heavy weight server-side framework that is not optimized for Android. Spring 是一个重量级的服务器端框架,没有针对 Android 进行优化。 The have some Android libraries, but those are for specific things like REST.有一些 Android 库,但这些是针对特定事物的,例如 REST。 If you need DI, use an Android framework such as RoboGuice .如果您需要 DI,请使用 Android 框架,例如RoboGuice

If you need DI and Spring, please give RoboSpring a try.如果您需要 DISpring,请尝试RoboSpring I have ported the Spring Framework to Android and tweaked the performance significantly!我已将 Spring 框架移植到 Android 并显着调整了性能! From the description:从描述来看:

RoboSpring is a (real) port of the Spring Framework to the Android platform. RoboSpring 是 Spring 框架到 Android 平台的(真实)端口。 Additionally it offers preliminary support for functionality introduced by RoboGuice like injecting View references into Activities and more.此外,它还为 RoboGuice 引入的功能提供了初步支持,例如将 View 引用注入到活动中等等。 RoboSpring is based on version 3.1.0 RELEASE of Spring's core , beans , context and aop components. RoboSpring 基于 Spring 的corebeanscontextaop组件的 3.1.0 RELEASE 版本。 It offers the following functionality:它提供以下功能:

  • Configure application components with a Spring configuration file (XML)使用 Spring 配置文件 (XML) 配置应用程序组件
  • Autowire your Android components with beans from the Spring application context.使用 Spring 应用程序上下文中的 bean 自动装配您的 Android 组件。
  • Inject the Android application context into your Spring Beans.将 Android 应用程序上下文注入您的 Spring Beans。
  • Inject views into Activities.将视图注入到活动中。
  • … and more … 和更多

Please see here: https://github.com/dthommes/RoboSpring请看这里: https : //github.com/dthommes/RoboSpring

RoboSpring - Android 控制反转

If you need the dependency injection only.如果您只需要依赖注入。 You may choose some lightweight framework like google guice.你可以选择一些轻量级的框架,比如 google guice。

Spring 有适用于 android 的库,但它为了有效地与一些 OAuth 进行 REST 通信,这里提供了详细信息spring-android和 spring 倡导者使用 RoboGuice 进行 DI 的开发人员,您可以从这里阅读它,对于硬核依赖注入,其RoboGuice是迄今为止最好的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM