如何配置Spring Boot应用程序侦听的TCP/IP端口,使其不使用默认端口8080。
当前回答
如果你正在使用spring命令行接口(CLI),使用——将命令与spring命令参数分开,来更改端口:
春天跑你好。Groovy -- --server.port=9000
spring-boot cli
其他回答
在文件应用程序。属性添加以下内容: server.port = 8888 这里需要经常提到的项目
通过编程方式,使用spring boot 2.1.5:
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory;
import org.springframework.stereotype.Component;
@Component
public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {
@Override
public void customize(ConfigurableServletWebServerFactory server) {
server.setPort(9000);
}
}
您还可以使用SERVER_PORT环境变量来配置Spring Boot端口。只需设置环境变量并重新启动应用程序:
set SERVER_PORT=9999 // on windows machine
export SERVER_PORT=9999 // on linux
请注意,如果你没有在系统范围内设置这些环境变量,你应该在同一个会话上运行引导应用程序。
有三种方法
1设置服务器。应用中的端口属性。属性文件
server.port = 8090
2在应用中设置服务器端口属性。yml文件
server:
port: 8090
3在“main method”中将属性设置为系统属性
System.setProperty("server.port","8090");
您可以通过更改application.properties来更改服务器配置中的许多其他内容。 比如会话超时,地址和端口等。参考下文
裁判:http://docs.spring.io/spring-boot/docs/1.4.x/reference/html/common-application-properties.html
我使用了其中的几个,如下所示。
server.session.timeout=1
server.port = 3029
server.address= deepesh
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何找到哪个程序正在使用端口80在Windows?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder