diff --git a/src/main/java/myblog/blog/main/ProfileController.java b/src/main/java/myblog/blog/main/ProfileController.java new file mode 100644 index 0000000..0a7a29a --- /dev/null +++ b/src/main/java/myblog/blog/main/ProfileController.java @@ -0,0 +1,31 @@ +package myblog.blog.main; + +import lombok.RequiredArgsConstructor; +import org.springframework.core.env.Environment; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.Arrays; +import java.util.List; + +@RequiredArgsConstructor +@RestController +public class ProfileController { + + private final Environment env; + + @GetMapping("/profile") + public String profile(){ + List profiles = Arrays.asList(env.getActiveProfiles()); + + List realProfiles = Arrays.asList("real", "real1", "real2"); + + String defaultProfile = profiles.isEmpty()? "default" : profiles.get(0); + + return profiles.stream() + .filter(realProfiles::contains) + .findAny() + .orElse(defaultProfile); + } + +} diff --git a/src/main/resources/application-real1.yml b/src/main/resources/application-real1.yml new file mode 100644 index 0000000..43eb57b --- /dev/null +++ b/src/main/resources/application-real1.yml @@ -0,0 +1,6 @@ +server: + port: 8081 + +spring: + profiles: + include: dev \ No newline at end of file diff --git a/src/main/resources/application-real2.yml b/src/main/resources/application-real2.yml new file mode 100644 index 0000000..f7005d9 --- /dev/null +++ b/src/main/resources/application-real2.yml @@ -0,0 +1,6 @@ +server: + port: 8082 + +spring: + profiles: + include: dev \ No newline at end of file