除了localhost之外,如何配置与Spring集成的嵌入式Tomcat来监听对IP地址的请求? [英] How to configure embedded Tomcat integrated with Spring to listen requests to IP address, besides localhost?

查看:537
本文介绍了除了localhost之外,如何配置与Spring集成的嵌入式Tomcat来监听对IP地址的请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行spring指南中的示例:构建RESTful Web服务

I am trying to run the example from the spring guide : Building a RESTful Web Service .

如果我打开 localhost:8080 /问候语。

但它不能很好如果我打开 192.168.1.111:8080/greeting 140.112.134.22:8080/greeting ,则建立连接,尽管我的计算机实际上在互联网上使用了这两个IP 。

But it cannot make connection if I open either 192.168.1.111:8080/greeting, or 140.112.134.22:8080/greeting instead, despite both IPs are actually used by my computer on the internet.

有人可以建议我如何在Spring中配置嵌入式Tomcat以接受其他IP地址上的HTTP请求,除了localhost(即127.0.0.1)?

Could someone suggest me how to configure the embedded Tomcat in Spring to accept HTTP request on other IP addresses, besides localhost(that is, 127.0.0.1)?

谢谢! :)

推荐答案

为了指定你想要Tomcat绑定的IP,我相信你可以简单地添加以下内容你的application.properties:

In order to specify a which IP you want Tomcat to bind too, I believe you can simply add the following to your application.properties:

server.address=<your_ip>
server.port=<your_port>

用IP替换< your_ip> 地址,你希望它听。这个和其他基本属性可以在 Spring Boot参考指南,附​​录A

Replacing <your_ip> with the IP address you want it to listen on. This, and other basic properties, can be found in the Spring Boot Reference Guide, Appendix A.

配置嵌入式Tomcat的另一种方法是通过实现代码来创建代码中的自定义配置器 EmbeddedServletContainerCustomizer 界面。您可以在中了解更多相关信息。 Spring Boot参考指南,第55.5-55.8节

The other way to configure the embedded Tomcat is to create a custom configurer in code by implementing the EmbeddedServletContainerCustomizer interface. You can read more about this in the Spring Boot Reference Guide, Section 55.5-55.8.

这篇关于除了localhost之外,如何配置与Spring集成的嵌入式Tomcat来监听对IP地址的请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆