简体   繁体   中英

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. You can find it on my 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.

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. , I get the expected 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. Locally (via localhost:8888), everything is still working perfectly. 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. Notice that my other J2EE services deployed to Tomcat container are perfectly reachable and usable remotely. 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 .

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? 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. Now I'd like to be able to deploy it in my existing Tomcat container... any idea?

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 . It mostly involves setting the maven packaging as a war. If your tomcat container is 6.0 or less, you would need to write a web.xml, otherwise you will to provide a 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.

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