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