【问题标题】:Spring boot standalone runs well on local but cannot be accessed on remote serverSpring Boot Standalone 在本地运行良好,但在远程服务器上无法访问
【发布时间】:2016-04-01 01:26:21
【问题描述】:

我在 Spring Boot 中实现了一个 hello world。

我正在使用嵌入式 tomcat,这是我在 application.properties 中的设置。

server.contextPath=/test
server.port=8080

我可以通过[localhost:8080/test/index.html] 毫无问题地访问它。

但是,我将jar文件上传到数字海洋上的ubuntu 14.04并正常启动后,我无法通过[machine-ipaddress:8080/test/index.html]访问它。它给了我一个 404 错误。

我可以看到应用程序正在监听端口。

tcp    0    0    0.0.0.0:8080    0.0.0.0:*    LISTEN    4284/java   

我检查了 iptable 设置,没有被阻止。

我也尝试停止此操作并在远程服务器上运行常规的空 tomcat,访问[machine-ipaddress:8080] 没有问题。

欢迎任何想法。

【问题讨论】:

    标签: java spring tomcat spring-boot


    【解决方案1】:

    发现问题。原因是我使用maven webapp archetype创建空项目,将index.html放在webapp下,打包成jar

    奇怪的是我可以使用 java -jar test.jar 在本地运行它。

    一旦我将 index.html 移动到资源/静态,它就可以在远程服务器上运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-08
      • 2014-11-29
      • 1970-01-01
      • 2013-08-14
      • 2017-06-16
      • 2020-08-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多