java Android 上的 Spring Boot?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39579540/
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
Spring Boot on Android?
提问by Lou Morda
Is it possible to run Spring Boot on an Android device?
是否可以在 Android 设备上运行 Spring Boot?
Right now I am successfully running a web service on localhost using Spring Boot which I've got building in IntelliJ IDEA. I need to get the same web service code running on an Android device. Is it possible to build the web service app into a JAR file that I can get running on an Android phone? I have a Google Nexus 6P running Android Nougat. I've done some limited research, and have found an application called JBED. So far I haven't been able to get this working.
现在,我使用在 IntelliJ IDEA 中构建的 Spring Boot 在本地主机上成功运行了一个 Web 服务。我需要在 Android 设备上运行相同的 Web 服务代码。是否可以将 Web 服务应用程序构建为可以在 Android 手机上运行的 JAR 文件?我有一台运行 Android Nougat 的 Google Nexus 6P。我做了一些有限的研究,发现了一个名为 JBED 的应用程序。到目前为止,我还没有能够让这个工作。
I've started from scratch and built the example JAR:
我从头开始构建示例 JAR:
gs-spring-boot-0.1.0.jar
and hopefully I can find a way to run this JAR. I'm guessing it probably won't work so if anyone has a better idea that would be great!
希望我能找到一种方法来运行这个 JAR。我猜它可能行不通,所以如果有人有更好的主意那就太好了!
回答by mross1080
Short answer is you're not gonna be able to directly run your spring boot application on your android phone. Spring boot is meant as a wrapper to quickly bootstrap Spring applications and is going to best serve you when building web based applications. As I see it you have two options.
简短的回答是你不能直接在你的安卓手机上运行你的 spring 启动应用程序。Spring boot 旨在作为快速引导 Spring 应用程序的包装器,并且在构建基于 Web 的应用程序时将为您提供最佳服务。在我看来,您有两种选择。
- Deploy your jar on the cloud somewhere(ec2,digitalocean, heroku, cloud foundry, etc.) and just access your Spring MVC app from the android browser. If you have some really complex logic in your boot app that you don't think you can port to android, you can still deploy your boot app in the cloud, and create a really "dumb" front end android application that consumes all of it's data from the spring boot app running externally.
- Port you current spring boot application to a true Spring for Android project. http://projects.spring.io/spring-android/. The tools are out there to help you port it over all you have to do is put the work in.
- 将您的 jar 部署在云上的某个地方(ec2、digitalocean、heroku、cloud Foundry 等),然后只需从 android 浏览器访问您的 Spring MVC 应用程序。如果您的启动应用程序中有一些非常复杂的逻辑,您认为您无法移植到 android,您仍然可以将启动应用程序部署在云中,并创建一个真正“愚蠢”的前端 android 应用程序,它会消耗所有这些来自外部运行的 Spring Boot 应用程序的数据。
- 将您当前的 Spring Boot 应用程序移植到真正的 Spring for Android 项目。 http://projects.spring.io/spring-android/。这些工具可以帮助您将其移植到您需要做的所有工作中。
回答by GiBi
You can use https://github.com/jetty-project/i-jettyto host servlet based apps in android. or embed i-jetty (replacing tomcat or netty) in your spring boot app
您可以使用https://github.com/jetty-project/i-jetty在 android 中托管基于 servlet 的应用程序。或将 i-jetty(替代 tomcat 或 netty)嵌入您的 Spring Boot 应用程序中