[英]Spring Boot Service works locally but not remotely
I'm trying to create a very simple RESTful Web Service with Spring Boot to perform NLP to the content passed as a parameter. 我正在尝试使用Spring Boot创建一个非常简单的RESTful Web服务,以对作为参数传递的内容执行NLP。 You can find it on my GitHub .
您可以在我的GitHub上找到它。
For some reason, I can't deploy it to my Tomcat container in my home server as a WAR ( see here ), therefore I decided at least to try to set it up as a runnable JAR. 由于某种原因,我无法将其作为WAR部署到我的家庭服务器中的Tomcat容器中( 请参阅此处 ),因此我决定至少尝试将其设置为可运行的JAR。
If I run it on my development machine by invoking: 如果通过调用在开发计算机上运行它:
java -jar -Xss32M -Xmx8G -XX:+UseG1GC -XX:+UseStringDeduplication ClearWS-0.1.0.jar
it works like a charm. 它就像一个魅力。 If I point my browser to http://localhost:8888/process?content=This%20is%20a%20test.
如果我将浏览器指向http:// localhost:8888 / process?content = This%20is%20a%20test。 , I get the expected JSON:
,我得到了预期的JSON:
{ "id": 1,
"sentences": [
{ "start": 0,
"end": 0,
"content": "This is a test.",
"tokens": [
{ "start": 0, "end": 4, "index": 0, "text": "This", "posTag": "DT", "chunkTag": "NP", "lemma": "this" },
{ "start": 5, "end": 7, "index": 1, "text": "is", "posTag": "VBZ", "chunkTag": "VP", "lemma": "be" },
{ "start": 8, "end": 9, "index": 2, "text": "a", "posTag": "DT", "chunkTag": "NP", "lemma": "a" },
{ "start": 10, "end": 14, "index": 3, "text": "test", "posTag": "NN", "chunkTag": "NP", "lemma": "test" },
{"start": 14, "end": 15, "index": 4, "text": ".", "posTag": ".", "chunkTag": ".", "lemma": "." } ],
"size": 5
} ]
}
Now, I've moved the ClearWS-0.1.0.jar
file to my home server and there I started it with the same command as above: no error messages. 现在,我将
ClearWS-0.1.0.jar
文件移到了我的家庭服务器,并在上面用与上面相同的命令启动了它:没有错误消息。 Locally (via localhost:8888), everything is still working perfectly. 在本地(通过localhost:8888),一切仍然正常运行。 If I try to use it remotely, however, it doesn't work: after some time the browser tells me that my attempt to connect has failed.
但是,如果我尝试远程使用它,它将无法正常工作:一段时间后,浏览器告诉我我的连接尝试失败。
That home server machine has a NATed address that doesn't change often, so I can hook it using no-ip.com
and access it anyway. 那台家用服务器机器的NAT地址不经常更改,因此我可以使用
no-ip.com
其挂接并以no-ip.com
访问它。 Notice that my other J2EE services deployed to Tomcat container are perfectly reachable and usable remotely. 请注意,我部署到Tomcat容器的其他J2EE服务完全可以访问并且可以远程使用。 I thought it might be the embedded Tomcat conflicting with the stand-alone one, so I shut the latter down but still I can't reach
ClearWS-0.1.0
. 我认为这可能是嵌入式Tomcat与独立的Tomcat发生冲突,因此我关闭了后者,但仍然无法达到
ClearWS-0.1.0
。
I'm starting to think that Spring understand that I still don't fully trust it, so it fails on me on purpose... Out of the joke, can anybody with a better understanding of Spring and networks help me to sort this problem out? 我开始认为Spring知道我仍然不完全信任它,所以它故意使我失败了……开个玩笑,对Spring和网络有更好的了解的人可以帮助我解决这个问题出来吗 Thanks in advance.
提前致谢。
Solution: I simply forgot to forward port 8888... Once added that configuration to my router, I was able to remotely use the service. 解决方案:我只是忘了转发端口8888 ...将配置添加到路由器后,便能够远程使用该服务。 Now I'd like to be able to deploy it in my existing Tomcat container... any idea?
现在,我希望能够将其部署到现有的Tomcat容器中……有什么主意吗?
If you really want to deploy it to a tomcat container, you need to create a war file as specified in the Spring Boot documentation . 如果您确实要将其部署到tomcat容器中,则需要按照Spring Boot文档中的说明创建一个war文件。 It mostly involves setting the maven packaging as a war.
它主要涉及将Maven包装定为战争。 If your tomcat container is 6.0 or less, you would need to write a web.xml, otherwise you will to provide a SpringBootServletInitializer .
如果您的tomcat容器为6.0或更小,则需要编写一个web.xml,否则将提供一个SpringBootServletInitializer 。
Personally, I don't see any benefit to running within a container these days. 就个人而言,这些天在容器中运行不会带来任何好处。 The movement in the java world now is for embedded servlet conatiners, which makes it much easier to run in the cloud or in a container like docker.
现在,Java世界的发展方向是嵌入式servlet容器,这使得在云中或在类似docker的容器中运行变得更加容易。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.