实现 EnvironmentAware setEnvironment()方法 即可
(注意)
不管配置在哪里,启动服务器是,就会执行该方法。
可以单独配置,也可以配置在 其他类中。
方法一。
com.zll.demo.config.MyEnvironment
方法二。
可以配置在 Contoller中。
com.zll.demo.controller.UserController
@RestController
public class UserController implements EnvironmentAware {
@Autowired
private UserService userService;
@GetMapping("/save")
public User save(User user){
userService.save(user);
return user;
}
@Override
public void setEnvironment(Environment environment) {
System.out.println("UserController");
System.out.println(environment.getProperty("JAVA_HOME"));
System.out.println(environment.getProperty("server.port"));
}
}
作者:没事偷着乐琅
来源:CSDN
原文:https://blog.csdn.net/zhanglinlang/article/details/78539692
版权声明:本文为博主原创文章,转载请附上博文链接!