前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Spring boot with Git version

Spring boot with Git version

作者头像
netkiller old
发布2018-03-05 18:34:51
6250
发布2018-03-05 18:34:51
举报
文章被收录于专栏:NetkillerNetkiller

本文节选自《Netkiller Java 手札》

5.23. Spring boot with Git version

Spring boot 每次升级打包发给运维操作,常常运维操作不当致使升级失败,开发怎样确认线上的jar/war包与升级包一致呢?

请看下面的解决方案

5.23.1. CommonRestController 公共控制器

所有 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());
	}
}			

5.23.2. VersionRestController 测试控制器

我们创建一个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.";
	}

}			

5.23.3. 创建 .gitattributes 文件

			# 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 $			
本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2017-06-01,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 Netkiller 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 5.23. Spring boot with Git version
    • 5.23.1. CommonRestController 公共控制器
      • 5.23.2. VersionRestController 测试控制器
        • 5.23.3. 创建 .gitattributes 文件
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档