Spring boot 每次升级打包发给运维操作,常常运维操作不当致使升级失败,开发怎样确认线上的jar/war包与升级包一致呢?
请看下面的解决方案
所有 RestController将会集成 CommonRestController
package cn.netkiller.api.rest; import org.springframework.http.HttpStatus; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseStatus; public class CommonRestController { @RequestMapping("ping") @ResponseStatus(HttpStatus.OK) public String welcome() { return "PONG"; } @RequestMapping("commit") public String commit() { return "$Id$"; } @RequestMapping("auth") @ResponseStatus(HttpStatus.OK) public String auth(@AuthenticationPrincipal final UserDetails user) { return String.format("%s: %s %s", user.getUsername(), user.getPassword(), user.getAuthorities()); } }
我们创建一个RestController并继承CommonRestController用来测试
package cn.netkiller.api.rest; @RestController @RequestMapping("/public/version") public class VersionRestController extends CommonRestController { private static final Logger logger = LoggerFactory.getLogger(VersionRestController.class); public VersionRestController() { // TODO Auto-generated constructor stub } @RequestMapping("welcome") @ResponseStatus(HttpStatus.OK) public String welcome() { return "Welcome to RestTemplate version 1.0."; } }
# vim .gitattributes src/main/java/cn/netkiller/api/rest/CommonRestController.java ident
使用curl命令调用commit接口可以显示当前war/jar最后一次提交的版本号码(你同样可以使用IE浏览器)
curl https://api.netkiller.cn/public/version/commit.json $Id: 929bc9e4c90b4d68c25dc693618f23b33fd6ba0f $
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。