Jython - Using Spring, Programming in Python?

人走茶凉 提交于 2019-12-05 02:19:01

问题


Ok, I'm a total newbie in this stuff.

So, I know Spring is really good as a framework, and I've been programming in Python for a while, so I was wondering if somehow I can use the Spring Framework but use code from Python.

I heard that maybe Jython was a good possibility for doing this, since it's (I think) Python running on the JVM, right?

So, is this possible? For me to use Spring while coding in Python?


回答1:


First, you're right that Jython is Python running in the JVM. And it's not just running in the JVM, it can interact with it in pretty much all the ways you want—use Java classes as Python classes, implement Java interfaces in a Python class and pass it to Java code, etc.

However, unlike some of the other JVM languages, Jython doesn't make any attempt to be semantically equivalent to Java (or to a superset of it). And of course Python and Java have very different idiomatic styles.

So, in short, just about anything is possible, but not everything is pleasant, as Marcin says.

For specifics about how Spring works with Jython, a quick Google search turned up See how Spring Python works with Jython. And in fact, it's part of a blog called "Spring Python", which is part of a site also called "Spring Python". It seems like this may be a port of Spring to Python rather than about using Jython with Spring. ("This project takes the concepts of Spring and applies it to the language and environment of Python. This includes pragmatic libraries and useful abstractions that quickly gets you back to working on the code that makes you money.") So, that might be another alternative for you.

The next search result was Jython Spring MVC Controllers.

And there were half a dozen other promising results. So, I think you'll have no problem finding information and examples.



来源:https://stackoverflow.com/questions/14388406/jython-using-spring-programming-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!