Create Project: profiles_applicationproperties (add Spring Boot Starters from the table)
Edit File: application.properties (inside src/main/resources, specifies active Profile)
Create Package: controllers (inside main package)
– Create Class: MyController.java (inside controllers package)
Create File: application-profile1.properties (inside src/main/resources, specifies Port 8081)
Create File: application-profile2properties (inside src/main/resources, specifies Port 8082)
application.properties (specifies active Profile)
spring.profiles.active = Profile1
application-profile1.properties (specifies Port 8081)
server.port = 8081
application-profile2properties (specifies Port 8082)
server.port = 8082
MyController.java
package com.ivoronline.profiles_applicationproperties.controllers;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class MyController {
@ResponseBody
@RequestMapping("/Hello")
public String hello() {
return "Hello from Controller";
}
}