简体   繁体   中英

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). 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.

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 .

If you need DI and Spring, please give RoboSpring a try. I have ported the Spring Framework to Android and tweaked the performance significantly! From the description:

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 , context and aop components. It offers the following functionality:

  • 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

Please see here: https://github.com/dthommes/RoboSpring

RoboSpring - Android 控制反转

If you need the dependency injection only. You may choose some lightweight framework like google guice.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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