Spring Boot Web:修改监听的IP地址和端口


#Spring Boot#


示例

我们基于 Spring Boot Web:通过 Hello World 入门 中的示例代码稍作更改。

项目结构:

.
├── build.gradle
└── src
    └── main
        ├── java
        │   └── hello
        │       ├── Application.java
        │       ├── Greeting.java
        │       └── GreetingController.java
        └── resources
            └── application.properties

其实很简单,在src/main/resources/ 增加文件 application.properties,内容如下:

server.address=127.0.0.1
server.port = 8090

运行 Application 类。

浏览器访问 http://127.0.0.1:8090/greeting ,可以看到:

{"id":1,"content":"Hello, World!"}

( 本文完 )