java android 应用中可以使用 Spring Framework 吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12946029/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can the Spring Framework be used in android applications?
提问by Mario Dennis
I am writing a android application which requires dependency injection in the data access API the application will need (I am implementing this API). I don't want to write the dependency injection manually. Therefore, I was thinking of using Spring. I realize that there are two versions of 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 应用程序,它需要在应用程序需要的数据访问 API 中进行依赖注入(我正在实现这个 API)。我不想手动编写依赖注入。因此,我在考虑使用Spring。我意识到有两个版本的spring。一个普通版和一个安卓版。可以在android应用程序中使用常规版本吗,因为我只想要依赖注入功能并且已经有了这些文件。
回答by Nikolay Elenkov
Don't. Spring is a heavy weight server-side framework that is not optimized for Android. The have some Android libraries, but those are for specific things like REST. If you need DI, use an Android framework such as RoboGuice.
别。Spring 是一个重量级的服务器端框架,没有针对 Android 进行优化。有一些 Android 库,但这些是针对特定事物的,例如 REST。如果您需要 DI,请使用 Android 框架,例如RoboGuice。
回答by Dr. Daniel Thommes
If you need DI andSpring, please give RoboSpringa try. I have ported the Spring Framework to Android and tweaked the performance significantly! From the description:
如果您需要 DI和Spring,请尝试RoboSpring。我已将 Spring 框架移植到 Android 并显着调整了性能!从描述来看:
RoboSpring is a (real) port of the Spring Framework to the Android platform. Additionally it offers preliminary support for functionality introduced by RoboGuice like injecting View references into Activities and more. RoboSpring is based on version 3.1.0 RELEASE of Spring's core, beans, contextand aopcomponents. It offers the following functionality:
RoboSpring 是 Spring 框架到 Android 平台的(真正的)端口。此外,它还为 RoboGuice 引入的功能提供了初步支持,例如将 View 引用注入到活动中等等。RoboSpring 基于 Spring 的core、beans、context和aop组件的3.1.0 RELEASE 版本。它提供以下功能:
- Configure application components with a Spring configuration file (XML)
- Autowire your Android components with beans from the Spring application context.
- Inject the Android application context into your Spring Beans.
- Inject views into Activities.
- … and more
- 使用 Spring 配置文件 (XML) 配置应用程序组件
- 使用 Spring 应用程序上下文中的 bean 自动装配您的 Android 组件。
- 将 Android 应用程序上下文注入您的 Spring Bean。
- 将视图注入到活动中。
- … 和更多
Please see here: https://github.com/dthommes/RoboSpring
请看这里:https: //github.com/dthommes/RoboSpring
回答by Drogba
If you need the dependency injection only. You may choose some lightweight framework like google guice.
如果您只需要依赖注入。你可以选择一些轻量级的框架,比如 google guice。
回答by y ramesh rao
Spring has libraries for android but its for efficiently doing REST communication with some OAuth the detailed information is available here spring-androidand the developers of spring advocate using RoboGuice for DI you can read about it from here, for hardcore dependency injection its RoboGuicewhich is by far the best out there.
Spring 有适用于 android 的库,但它为了有效地与一些 OAuth 进行 REST 通信,这里提供了详细信息spring-android和 spring 倡导者使用 RoboGuice 进行 DI 的开发人员,您可以从这里阅读它,对于硬核依赖注入,其RoboGuice是迄今为止最好的。