如何配置Spring Boot应用程序侦听的TCP/IP端口,使其不使用默认端口8080。
当前回答
正如大家所说,您可以在application.properties中指定 服务器。Port = 9000(可以是任何其他值) 如果您在项目中使用弹簧执行器,默认情况下它指向 8080,如果你想改变它,在应用程序中。属性提 管理。Port = 9001(可以是任何其他值)
其他回答
由于Spring Boot提供了各种配置外部化机制(通过各种PropertySource实现和/或按顺序连接到Environment对象的处理器),您可以通过以下方法设置jar存档之外的任何属性:
Pass property through command line argument as application argument java -jar <path/to/my/jar> --server.port=7788 From property in SPRING_APPLICATION_JSON (Spring Boot 1.3.0+) Define environment variable in U*IX shell: SPRING_APPLICATION_JSON='{"server.port":7788}' java -jar <path/to/my/jar> By using Java system property: java -Dspring.application.json='{"server.port":7788}' -jar <path/to/my/jar> Pass through command line argument: java -jar <path/to/my/jar> --spring.application.json='{"server.port":7788}' Define JVM system property java -Dserver.port=7788 -jar <path/to/my/jar> Define OS environment variable U*IX Shell SERVER_PORT=7788 java -jar <path/to/my/jar> Windows SET SERVER_PORT=7788 java -jar <path/to/my/jar> Place property in ./config/application.properties configuration file server.port=7788 and run: java -jar <path/to/my/jar> Place property in ./config/application.yaml server: port: 7788 and run: java -jar <path/to/my/jar> Place property in ./application.properties server.port=7788 and run: java -jar <path/to/my/jar> Place property in ./application.yaml server: port: 7788 and run: java -jar <path/to/my/jar>
您可以将上述方法组合在一起,列表中的前一个配置优先于后一个配置。
例如:
SERVER_PORT=2266 java -Dserver.port=5566 -jar <path/to/my/jar> --server.port=7788
服务器将在端口7788上启动并监听。
这非常有用,在PropertySources中提供优先级较低的默认属性(通常打包在存档中或编码在源代码中),然后在运行时环境中覆盖它。这就是Spring Boot的设计理念:
坚持己见,但当需求开始偏离默认值时,要迅速离开。
SERVER_NAME到server.name的转换由放松绑定完成。
您可以在应用程序中配置端口。spring引导项目的资源文件夹中的属性文件。
server.port="port which you need"
您可以在下面的方法中添加端口。
执行->配置命令 在application.xml中添加server.port=XXXX
大多数情况下,springboot运行在端口:8080上,因为使用了嵌入式Tomcat。在某些情况下,它可能抛出一个已经在使用的错误端口8080。为了避免这种问题,我们可以配置服务器端口。
使用application.properties
添加server.port = 9898
在运行时配置
使用以下参数运行应用程序。
spring-boot:跑-Drun.jvmArguments = ' -Dserver.port = 8081 '
打开应用程序。属性文件。并在属性文件中添加下面的属性。
server.port = 1443
这将很好地工作,您可以根据自己的愿望设置任何端口号。
推荐文章
- Java 8接口方法中不允许“同步”的原因是什么?
- 如何找到Java堆大小和内存使用(Linux)?
- Spring引导——不是托管类型
- Spring Boot YAML配置的字符串列表
- 使用Enum实现单例(Java)
- RabbitMQ与通道和连接之间的关系
- buildSessionFactory()配置方法在Hibernate中已弃用?
- Spring MVC -如何获得所有的请求参数在一个地图在Spring控制器?
- 如何在Java中按两个字段排序?
- 文件之间的差异。路径中的分隔符和斜杠
- 在方法参数中使用NotNull注释
- Spring MVC中处理可选参数的@RequestParam
- Tomcat:如何查找正在运行的Tomcat版本?
- “java”、“javaw”和“javaws”之间有什么区别?
- 将Date对象转换为日历对象