diff --git a/spring-boot-modules/spring-boot-environment/src/main/java/com/baeldung/prefix/PrefixApplication.java b/spring-boot-modules/spring-boot-environment/src/main/java/com/baeldung/prefix/PrefixApplication.java new file mode 100644 index 0000000000..29fe3d8930 --- /dev/null +++ b/spring-boot-modules/spring-boot-environment/src/main/java/com/baeldung/prefix/PrefixApplication.java @@ -0,0 +1,14 @@ +package com.baeldung.prefix; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class PrefixApplication { + + public static void main(String[] args) { + SpringApplication application = new SpringApplication(PrefixApplication.class); + application.setEnvironmentPrefix("prefix"); + application.run(args); + } +} diff --git a/spring-boot-modules/spring-boot-environment/src/main/java/com/baeldung/prefix/PrefixController.java b/spring-boot-modules/spring-boot-environment/src/main/java/com/baeldung/prefix/PrefixController.java new file mode 100644 index 0000000000..00b728c7ae --- /dev/null +++ b/spring-boot-modules/spring-boot-environment/src/main/java/com/baeldung/prefix/PrefixController.java @@ -0,0 +1,19 @@ +package com.baeldung.prefix; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; + +@Controller +public class PrefixController { + + @Value(value = "${server.port}") + private int serverPort; + + @GetMapping("/prefix") + public String getServerPortInfo(final Model model) { + model.addAttribute("serverPort", serverPort); + return "prefix"; + } +} diff --git a/spring-boot-modules/spring-boot-environment/src/main/resources/templates/prefix.html b/spring-boot-modules/spring-boot-environment/src/main/resources/templates/prefix.html new file mode 100644 index 0000000000..7bb5a76537 --- /dev/null +++ b/spring-boot-modules/spring-boot-environment/src/main/resources/templates/prefix.html @@ -0,0 +1,9 @@ + + + + Prefix Example Page + + +It is working as we expected. Your server is running at port : + + \ No newline at end of file