Spring RESTful Web Service的端口绑定

问题描述 投票:4回答:2

我已经使用构建RESTful Web服务教程来为我的目的构建WebService。 这很容易,但现在我很难配置WebService应该绑定的端口。 此项目中没有config.xml或任何要配置的内容。 任何人都可以给我一个关于如何配置WebService端口的提示吗?

因为这些细节可能会有所帮助。 我正在使用下面的代码启动服务器,其中包含@EnableAutoConfiguration标记。 配置由Spring Boot完成。

@ComponentScan
@EnableAutoConfiguration
public class ServerStarter{

public static void main(String[] args) {
        SpringApplication.run(ServerStarter.class, args);
    }
}
spring web-services
2个回答
5
投票

要配置端口,可以通过在“src / main / resources”下的“application.properties”文件中编写以下内容来设置server.port和management.port属性:

server.port = 9000
management.port = 9001

同样,如果您需要指定管理地址:

management.address = 127.0.0.1

您可以为服务器和管理服务器设置更多属性。 请参阅spring-boot的文档: http//docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/


2
投票

对于快速而肮脏的解决方案,您可以使用命令行选项参数( ):

 --server.port=9000 
© www.soinside.com 2019 - 2024. All rights reserved.