fix: use env to get properties
This commit is contained in:
parent
098701a66d
commit
727b34ea22
|
@ -1,6 +1,7 @@
|
||||||
package com.baeldung.prefix;
|
package com.baeldung.prefix;
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
@ -8,12 +9,12 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@Controller
|
@Controller
|
||||||
public class PrefixController {
|
public class PrefixController {
|
||||||
|
|
||||||
@Value(value = "${server.port}")
|
@Autowired
|
||||||
private int serverPort;
|
private Environment environment;
|
||||||
|
|
||||||
@GetMapping("/prefix")
|
@GetMapping("/prefix")
|
||||||
public String getServerPortInfo(final Model model) {
|
public String getServerPortInfo(final Model model) {
|
||||||
model.addAttribute("serverPort", serverPort);
|
model.addAttribute("serverPort", environment.getProperty("server.port"));
|
||||||
return "prefix";
|
return "prefix";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue