feat: env variable prefixes spring boot app (#11323)
This commit is contained in:
parent
8f79432600
commit
2dfdb51592
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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";
|
||||
}
|
||||
}
|
|
@ -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>
|
Loading…
Reference in New Issue