2.25. Spring boot with Git version

简介:

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

请看下面的解决方案

2.25.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());
	}
}
			
			

2.25.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.";
	}

}
			
			

2.25.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 $
			
			



原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

目录
相关文章
|
19天前
|
Java 应用服务中间件 Maven
SpringBoot 项目瘦身指南
SpringBoot 项目瘦身指南
71 0
|
19天前
|
安全 Java 应用服务中间件
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置
35 0
江帅帅:Spring Boot 底层级探索系列 03 - 简单配置
|
19天前
|
XML Java C++
【Spring系列】Sping VS Sping Boot区别与联系
【4月更文挑战第2天】Spring系列第一课:Spring Boot 能力介绍及简单实践
41 0
【Spring系列】Sping VS Sping Boot区别与联系
|
19天前
|
JSON Java Maven
SpringBoot使用git-commit-id-maven-plugin打包
【2月更文挑战第1天】 git-commit-id-maven-plugin 是一个maven 插件,用来在打包的时候将git-commit 信息打进jar中。 这样做的好处是可以将发布的某版本和对应的代码关联起来,方便查阅和线上项目的维护。至于它的作用,用官方说法,这个功能对于大型分布式项目来说是无价的。
104 0
|
19天前
|
XML 监控 druid
【Java专题_02】springboot+mybatis+pagehelper分页插件+druid数据源详细教程
【Java专题_02】springboot+mybatis+pagehelper分页插件+druid数据源详细教程
70 0
|
19天前
|
开发框架 Java .NET
SpringBoot3中的属性绑定注解和YMAL配置文件、日志
SpringBoot3中的属性绑定注解和YMAL配置文件、日志
|
19天前
|
Java
springboot项目打包瘦身
springboot项目打包瘦身
|
7月前
|
Java 测试技术
Springboot集成JUnit5优雅进行单元测试
Springboot集成JUnit5优雅进行单元测试
100 0
|
11月前
|
Java Maven
【Springboot】创建boot工程spring-boot-maven-plugin报红、出错_解决方案
【Springboot】创建boot工程spring-boot-maven-plugin报红、出错_解决方案
331 0
|
11月前
|
SQL druid 前端开发
让SpringBoot不需要Controller、Service、DAO、Mapper,卧槽!这款工具绝了!
让SpringBoot不需要Controller、Service、DAO、Mapper,卧槽!这款工具绝了!