feat: env variable prefixes spring boot app (#11323)

This commit is contained in:
lucaCambi77 2021-10-13 18:21:35 +02:00 committed by GitHub
parent 8f79432600
commit 2dfdb51592
3 changed files with 42 additions and 0 deletions

View File

@ -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);
}
}

View File

@ -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";
}
}

View File

@ -0,0 +1,9 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<title>Prefix Example Page</title>
</head>
<body>
It is working as we expected. Your server is running at port : <b th:text="${serverPort}"></b>
</body>
</html>