application.yml文件:
server:
port: 8181
spring:
profiles: demo1
---
server:
port: 8182
spring:
profiles: demo2
---
server:
port: 8183
spring:
profiles: demo3
---
类:
package com.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Configuration
public class TestController {
@Value("${spring.profiles}")
private String profile;
@Value("${server.port}")
private String port; //端口
@RequestMapping("/")
public Object test1(){
return "test1 - " + profile + " : " + port;
}
}